Permalink
Browse files

refactoring sequencer into new file

  • Loading branch information...
1 parent 2a5359c commit ec71c0023ccba47fc707efa923ac84431ac9b9eb @interstar committed Jan 3, 2012
Showing with 92 additions and 77 deletions.
  1. +1 −0 main.cpp
  2. +51 −0 sequence.cpp
  3. +37 −0 sequence.h
  4. +0 −44 waveflavour.cpp
  5. +3 −33 waveflavour.h
View
1 main.cpp
@@ -1,5 +1,6 @@
#include "maximilian.h"
#include "waveflavour.h"
+#include "sequence.h"
#include <math.h>
#include <stdio.h>
View
51 sequence.cpp
@@ -0,0 +1,51 @@
+#include "sequence.h"
+#include <math.h>
+#include <stdio.h>
+
+#define MAX_INSTRUMENTS 10
+
+// __Sequencer______________________________________________________________________________
+//
+void Sequencer::start(int l, int n[][2], int s) {
+ printf("Starting sequencer\n");
+ len = l;
+ speed = s;
+ printf("Len: %d, Speed: %d\n",len,speed);
+
+ notes = new Note[len];
+ for (int i=0;i<len;i++) {
+ notes[i].note = n[i][0];
+ notes[i].duration = n[i][1];
+ printf("%d) %d,%d\n",i,notes[i].note,notes[i].duration);
+ }
+
+ trigger=1;
+ currentNote = notes[0].note;
+ currentDuration = notes[0].duration;
+
+ noteTrigger.start(1,len);
+ noteTrigger.x = noteTrigger.max;
+ tick.start(1,speed*currentDuration);
+ printf("Sequencer started with speed: %d, note: %d and duration: %d, %d\n",speed,currentNote,currentDuration,tick.max);
+}
+
+void Sequencer::step() {
+ tick.next();
+ if (tick.wrapped()) {
+ printf("*");
+ advanceNote();
+ trigger = true;
+ } else {
+ trigger = false;
+ }
+}
+
+void Sequencer::advanceNote() {
+ int c = noteTrigger.next();
+ currentNote = notes[c].note;
+ currentDuration = notes[c].duration;
+ printf("%d: %d, %d\n",c,currentNote,currentDuration);
+ tick.start(1,speed*currentDuration);
+}
+
+
View
37 sequence.h
@@ -0,0 +1,37 @@
+#include "waveflavour.h"
+
+#define MAX_INSTRUMENTS 10
+
+typedef struct {
+ int note;
+ int duration;
+} Note;
+
+
+class Sequencer {
+ public :
+ PhaseCounter tick;
+ PhaseCounter noteTrigger;
+ int len,speed;
+ Note* notes;
+ int currentNote,currentDuration;
+
+ bool trigger;
+ void start(int l, int n[][2], int speed);
+ void step();
+ void advanceNote();
+};
+
+
+/*
+class Score {
+ int noSequences;
+ Sequencer sequences[MAX_INSTRUMENTS];
+ Instrument instruments[MAX_INSTRUMENTS];
+
+ void setup();
+ void addSequence(int len, int n[][2], int speed);
+ Instrument* addInstrument(int waveform1, int waveform2, int noVoices, int* pitchOffsets, int seqNo);
+ void play();
+}
+*/
View
44 waveflavour.cpp
@@ -189,48 +189,4 @@ double Instrument::next(int pitch, int trigger) {
return o;
}
-// __Sequencer______________________________________________________________________________
-//
-void Sequencer::start(int l, int n[][2], int s) {
- printf("Starting sequencer\n");
- len = l;
- speed = s;
- printf("Len: %d, Speed: %d\n",len,speed);
-
- notes = new Note[len];
- for (int i=0;i<len;i++) {
- notes[i].note = n[i][0];
- notes[i].duration = n[i][1];
- printf("%d) %d,%d\n",i,notes[i].note,notes[i].duration);
- }
-
- trigger=1;
- currentNote = notes[0].note;
- currentDuration = notes[0].duration;
-
- noteTrigger.start(1,len);
- noteTrigger.x = noteTrigger.max;
- tick.start(1,speed*currentDuration);
- printf("Sequencer started with speed: %d, note: %d and duration: %d, %d\n",speed,currentNote,currentDuration,tick.max);
-}
-
-void Sequencer::step() {
- tick.next();
- if (tick.wrapped()) {
- printf("*");
- advanceNote();
- trigger = true;
- } else {
- trigger = false;
- }
-}
-
-void Sequencer::advanceNote() {
- int c = noteTrigger.next();
- currentNote = notes[c].note;
- currentDuration = notes[c].duration;
- printf("%d: %d, %d\n",c,currentNote,currentDuration);
- tick.start(1,speed*currentDuration);
-}
-
View
36 waveflavour.h
@@ -1,17 +1,13 @@
#include "maximilian.h"
+#ifndef TABLE_LEN
+
#define TABLE_LEN 512
#define GENEROUS_TABLE_LEN 514
-#define MAX_INSTRUMENTS 10
#define SIN -100
#define RAMP -99
-typedef struct {
- int note;
- int duration;
-} Note;
-
class PhaseCounter {
public :
@@ -80,30 +76,4 @@ class Instrument {
};
-class Sequencer {
- public :
- PhaseCounter tick;
- PhaseCounter noteTrigger;
- int len,speed;
- Note* notes;
- int currentNote,currentDuration;
-
- bool trigger;
- void start(int l, int n[][2], int speed);
- void step();
- void advanceNote();
-};
-
-
-/*
-class Score {
- int noSequences;
- Sequencer sequences[MAX_INSTRUMENTS];
- Instrument instruments[MAX_INSTRUMENTS];
-
- void setup();
- void addSequence(int len, int n[][2], int speed);
- Instrument* addInstrument(int waveform1, int waveform2, int noVoices, int* pitchOffsets, int seqNo);
- void play();
-}
-*/
+#endif

0 comments on commit ec71c00

Please sign in to comment.