int notehandler(void *, char *note) { if(strncmp(note, "sys:", 4) == 0) return 0; if(strncmp(note, "emu:", 4) == 0) exits(note); addnote(note); return 1; }
int main() { // turn all keys off for (int i=0; i<13; ++i) keys[i] = 0; // reset loops[] for (int i=0; i<10; ++i) loops[i] = NULL; BPM = 500; // default tempo controller.baud(9600); pc.printf("\r\ninit\r\n"); // load demo tune //Demo Song Hardcode Loop* demo = setloop(2); addnote(demo, currentnote); threadedloop(demo); //free all the notes?? Note* temp; while (currentnote->next) { temp = currentnote; currentnote = currentnote->next; delete temp; } // interactive section BPM = 150; // default tempo int looper[] = {A, C}; Loop* loop1 = setloop(-1); loops[0] = loop1; addnote(loop1, hi(G), 1, 1); addnote(loop1, F, 1, 1); addnote(loop1, E, 1, 1); addnote(loop1, F, 1, 2); addnote(loop1, hi(A), 1, 1); addnote(loop1, REST, 4, 1); //Additional Loops //int highnote[] = {hi(E)}; //int lownote[] = {G}; //Note* freehi = setnote(1, highnote, 1, 1); //Note* freelo = setnote(1, lownote, 1, 1); printf("allocated all loops!\r\n"); // ready to play // everything has to be part of a Loop in order to play //Thread t9(freenote, freehi); //Thread t10(freenote, freelo); //t1.terminate(); // test to terminate a loop from main thread while(1) { //if (controller.readable()) { int loopnum; if (controller.scanf("\n%d", &loopnum)) { // code to turn on/off the loop OR play the free note pc.printf("received %d\r\n", loopnum); loopnum--; if (loopthreads[loopnum]) { pc.printf("end loop %d\r\n", loopnum); loopthreads[loopnum]->terminate(); delete loopthreads[loopnum]; // helps with memory loopthreads[loopnum] = NULL; } else { pc.printf("start loop %d\r\n", loopnum); loopthreads[loopnum] = new Thread(threadedloop, loops[loopnum]); } } //} } }