Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

refactoring sequencer into new file

  • Loading branch information...
commit ec71c0023ccba47fc707efa923ac84431ac9b9eb 1 parent 2a5359c
phil jones authored
1  main.cpp
... ... @@ -1,5 +1,6 @@
1 1 #include "maximilian.h"
2 2 #include "waveflavour.h"
  3 +#include "sequence.h"
3 4
4 5 #include <math.h>
5 6 #include <stdio.h>
51 sequence.cpp
... ... @@ -0,0 +1,51 @@
  1 +#include "sequence.h"
  2 +#include <math.h>
  3 +#include <stdio.h>
  4 +
  5 +#define MAX_INSTRUMENTS 10
  6 +
  7 +// __Sequencer______________________________________________________________________________
  8 +//
  9 +void Sequencer::start(int l, int n[][2], int s) {
  10 + printf("Starting sequencer\n");
  11 + len = l;
  12 + speed = s;
  13 + printf("Len: %d, Speed: %d\n",len,speed);
  14 +
  15 + notes = new Note[len];
  16 + for (int i=0;i<len;i++) {
  17 + notes[i].note = n[i][0];
  18 + notes[i].duration = n[i][1];
  19 + printf("%d) %d,%d\n",i,notes[i].note,notes[i].duration);
  20 + }
  21 +
  22 + trigger=1;
  23 + currentNote = notes[0].note;
  24 + currentDuration = notes[0].duration;
  25 +
  26 + noteTrigger.start(1,len);
  27 + noteTrigger.x = noteTrigger.max;
  28 + tick.start(1,speed*currentDuration);
  29 + printf("Sequencer started with speed: %d, note: %d and duration: %d, %d\n",speed,currentNote,currentDuration,tick.max);
  30 +}
  31 +
  32 +void Sequencer::step() {
  33 + tick.next();
  34 + if (tick.wrapped()) {
  35 + printf("*");
  36 + advanceNote();
  37 + trigger = true;
  38 + } else {
  39 + trigger = false;
  40 + }
  41 +}
  42 +
  43 +void Sequencer::advanceNote() {
  44 + int c = noteTrigger.next();
  45 + currentNote = notes[c].note;
  46 + currentDuration = notes[c].duration;
  47 + printf("%d: %d, %d\n",c,currentNote,currentDuration);
  48 + tick.start(1,speed*currentDuration);
  49 +}
  50 +
  51 +
37 sequence.h
... ... @@ -0,0 +1,37 @@
  1 +#include "waveflavour.h"
  2 +
  3 +#define MAX_INSTRUMENTS 10
  4 +
  5 +typedef struct {
  6 + int note;
  7 + int duration;
  8 +} Note;
  9 +
  10 +
  11 +class Sequencer {
  12 + public :
  13 + PhaseCounter tick;
  14 + PhaseCounter noteTrigger;
  15 + int len,speed;
  16 + Note* notes;
  17 + int currentNote,currentDuration;
  18 +
  19 + bool trigger;
  20 + void start(int l, int n[][2], int speed);
  21 + void step();
  22 + void advanceNote();
  23 +};
  24 +
  25 +
  26 +/*
  27 +class Score {
  28 + int noSequences;
  29 + Sequencer sequences[MAX_INSTRUMENTS];
  30 + Instrument instruments[MAX_INSTRUMENTS];
  31 +
  32 + void setup();
  33 + void addSequence(int len, int n[][2], int speed);
  34 + Instrument* addInstrument(int waveform1, int waveform2, int noVoices, int* pitchOffsets, int seqNo);
  35 + void play();
  36 +}
  37 +*/
44 waveflavour.cpp
@@ -189,48 +189,4 @@ double Instrument::next(int pitch, int trigger) {
189 189 return o;
190 190 }
191 191
192   -// __Sequencer______________________________________________________________________________
193   -//
194   -void Sequencer::start(int l, int n[][2], int s) {
195   - printf("Starting sequencer\n");
196   - len = l;
197   - speed = s;
198   - printf("Len: %d, Speed: %d\n",len,speed);
199   -
200   - notes = new Note[len];
201   - for (int i=0;i<len;i++) {
202   - notes[i].note = n[i][0];
203   - notes[i].duration = n[i][1];
204   - printf("%d) %d,%d\n",i,notes[i].note,notes[i].duration);
205   - }
206   -
207   - trigger=1;
208   - currentNote = notes[0].note;
209   - currentDuration = notes[0].duration;
210   -
211   - noteTrigger.start(1,len);
212   - noteTrigger.x = noteTrigger.max;
213   - tick.start(1,speed*currentDuration);
214   - printf("Sequencer started with speed: %d, note: %d and duration: %d, %d\n",speed,currentNote,currentDuration,tick.max);
215   -}
216   -
217   -void Sequencer::step() {
218   - tick.next();
219   - if (tick.wrapped()) {
220   - printf("*");
221   - advanceNote();
222   - trigger = true;
223   - } else {
224   - trigger = false;
225   - }
226   -}
227   -
228   -void Sequencer::advanceNote() {
229   - int c = noteTrigger.next();
230   - currentNote = notes[c].note;
231   - currentDuration = notes[c].duration;
232   - printf("%d: %d, %d\n",c,currentNote,currentDuration);
233   - tick.start(1,speed*currentDuration);
234   -}
235   -
236 192
36 waveflavour.h
... ... @@ -1,17 +1,13 @@
1 1 #include "maximilian.h"
2 2
  3 +#ifndef TABLE_LEN
  4 +
3 5 #define TABLE_LEN 512
4 6 #define GENEROUS_TABLE_LEN 514
5   -#define MAX_INSTRUMENTS 10
6 7
7 8 #define SIN -100
8 9 #define RAMP -99
9 10
10   -typedef struct {
11   - int note;
12   - int duration;
13   -} Note;
14   -
15 11
16 12 class PhaseCounter {
17 13 public :
@@ -80,30 +76,4 @@ class Instrument {
80 76 };
81 77
82 78
83   -class Sequencer {
84   - public :
85   - PhaseCounter tick;
86   - PhaseCounter noteTrigger;
87   - int len,speed;
88   - Note* notes;
89   - int currentNote,currentDuration;
90   -
91   - bool trigger;
92   - void start(int l, int n[][2], int speed);
93   - void step();
94   - void advanceNote();
95   -};
96   -
97   -
98   -/*
99   -class Score {
100   - int noSequences;
101   - Sequencer sequences[MAX_INSTRUMENTS];
102   - Instrument instruments[MAX_INSTRUMENTS];
103   -
104   - void setup();
105   - void addSequence(int len, int n[][2], int speed);
106   - Instrument* addInstrument(int waveform1, int waveform2, int noVoices, int* pitchOffsets, int seqNo);
107   - void play();
108   -}
109   -*/
  79 +#endif

0 comments on commit ec71c00

Please sign in to comment.
Something went wrong with that request. Please try again.