// ========================================================================== // in C. by Terry Riley // // - initial haxoration by Rob Hamilton, http://ccrma.stanford.edu/~rob // // - ideas and code fragments liberally borrowed from numerous standard // ChucK example files, as well as more specifically the example at // http://wiki.cs.princeton.edu/index.php/Bwv645.ck // ========================================================================== Event pulse; 0 => int dbug;// set to 0 for no debug messages 0 => int g_octaveDrop; // toggle to drop cells 8vb fun void debug(string loc, string msg) { if(dbug==1) <<>>; } // create array of [StkInstrument] StkInstrument stkInstruments[7]; new Rhodey @=> Rhodey @ inst1; new StifKarp @=> StifKarp @ inst2; new ModalBar @=> ModalBar @ inst3; new Wurley @=> Wurley @ inst4; new Sitar @=> Sitar @ inst5; new Mandolin @=> Mandolin @ inst6; new Moog @=> Moog @ inst7; inst1 @=> stkInstruments[0]; inst2 @=> stkInstruments[1]; inst3 @=> stkInstruments[2]; inst4 @=> stkInstruments[3]; inst5 @=> stkInstruments[4]; inst6 @=> stkInstruments[5]; inst7 @=> stkInstruments[6]; // select instrument here: // 1: Rhodes // 2: StifKarp // 3: ModalBar // 4: Wurley // 5: Sitar // 6: Mandolin // 7: Moog 3 => int selectedStkInstrument; StkInstrument currentInstrument; stkInstruments[selectedStkInstrument-1] @=> currentInstrument; currentInstrument => JCRev reverb => Gain master => dac; 0. => master.gain; .01 => reverb.mix; 0 => int loopValue; // loop flag 0 => int cellPlaying; // if a cell is currently playing flag 0 => int started; 0 => int button_loop; // 1: button was pressed while loop was selected, clear when loop turned off // MAUI HEADER SECTION =============================================== // vertical offset for objects in column 0 => int gVOffset; fun int voffset() { return voffset(0); } fun int voffset(int height) { gVOffset + height => gVOffset; return gVOffset; } 4 => int gHOffset; fun int hoffset() { return hoffset(0); } fun int hoffset(int width) { gHOffset + width => gHOffset; return gHOffset; } // led objects // led a: pulses to sync beat (blue) // led b: turns/stays green when cell is being played MAUI_LED a, b; MAUI_Button currentCell, playpause, loop, prev, next; MAUI_Slider volume_slider; // view object MAUI_View v; // set the view size v.size( 240, 754 ); v.name( "iNc" ); 40 => int ledHeight => int ledWidth; // initialize color, size position of first led a.color( a.blue ); a.size( ledWidth, ledWidth ); a.position( 10, voffset(10)); v.addElement( a ); b.color( b.green ); b.size( ledWidth, ledWidth ); b.position( 60, voffset(0)); v.addElement( b ); currentCell.pushType(); currentCell.size( 70, 70 ); currentCell.position( 170, 0 ); currentCell.name( "[-] " ); v.addElement( currentCell ); loop.toggleType(); loop.size( 100, 65 ); loop.position( 0, voffset(40) ); loop.name( "loop" ); v.addElement( loop ); prev.pushType(); prev.size( 100, 65 ); prev.position( 70, voffset(0) ); prev.name( "prev" ); v.addElement( prev ); next.pushType(); next.size( 100, 65 ); next.position( 140, voffset(0) ); next.name( "next" ); v.addElement( next ); playpause.pushType(); playpause.size( 240, 80 ); playpause.position( 0, voffset(35) ); playpause.name( "play" ); v.addElement( playpause ); volume_slider.size( 240, 80 ); volume_slider.position( 0, voffset(70) ); volume_slider.name( "Volume" ); volume_slider.range( 0, 1 ); volume_slider.value( master.gain() ); v.addElement( volume_slider ); MAUI_Button bt1, bt2, bt3, bt4, bt5, bt6, bt7, bt8, bt9, bt10, bt11, bt12, bt13, bt14, bt15, bt16, bt17, bt18, bt19, bt20, bt21, bt22, bt23, bt24, bt25, bt26, bt27, bt28, bt29, bt30, bt31, bt32, bt33, bt34, bt35, bt36, bt37, bt38, bt39, bt40, bt41, bt42, bt43, bt44, bt45, bt46, bt47, bt48, bt49, bt50, bt51, bt52, bt53; MAUI_Button octaveDrop, twooctaveDrop;//, octaveUp; 70 => int btX; 70 => int btY; 40 => int cellVspace; 40 => int cellHspace; bt1.pushType(); bt1.size(btX, btY); bt1.position(hoffset(), voffset(70)); bt1.name("1"); v.addElement(bt1); bt2.pushType(); bt2.size(btX, btY); bt2.position(hoffset(cellHspace), voffset(0)); bt2.name("2"); v.addElement(bt2); bt3.pushType(); bt3.size(btX, btY); bt3.position(hoffset(cellHspace), voffset(0)); bt3.name("3"); v.addElement(bt3); bt4.pushType(); bt4.size(btX, btY); bt4.position(hoffset(cellHspace), voffset(0)); bt4.name("4"); v.addElement(bt4); bt5.pushType(); bt5.size(btX, btY); bt5.position(hoffset(cellHspace), voffset(0)); bt5.name("5"); v.addElement(bt5); 4 => gHOffset; bt6.pushType(); bt6.size(btX, btY); bt6.position(hoffset(), voffset(cellVspace)); bt6.name("6"); v.addElement(bt6); bt7.pushType(); bt7.size(btX, btY); bt7.position(hoffset(cellHspace), voffset(0)); bt7.name("7"); v.addElement(bt7); bt8.pushType(); bt8.size(btX, btY); bt8.position(hoffset(cellHspace), voffset(0)); bt8.name("8"); v.addElement(bt8); bt9.pushType(); bt9.size(btX, btY); bt9.position(hoffset(cellHspace), voffset(0)); bt9.name("9"); v.addElement(bt9); bt10.pushType(); bt10.size(btX, btY); bt10.position(hoffset(cellHspace), voffset(0)); bt10.name("10"); v.addElement(bt10); 4 => gHOffset; bt11.pushType(); bt11.size(btX, btY); bt11.position(hoffset(), voffset(cellVspace)); bt11.name("11"); v.addElement(bt11); bt12.pushType(); bt12.size(btX, btY); bt12.position(hoffset(cellHspace), voffset(0)); bt12.name("12"); v.addElement(bt12); bt13.pushType(); bt13.size(btX, btY); bt13.position(hoffset(cellHspace), voffset(0)); bt13.name("13"); v.addElement(bt13); bt14.pushType(); bt14.size(btX, btY); bt14.position(hoffset(cellHspace), voffset(0)); bt14.name("14"); v.addElement(bt14); bt15.pushType(); bt15.size(btX, btY); bt15.position(hoffset(cellHspace), voffset(0)); bt15.name("15"); v.addElement(bt15); 4 => gHOffset; bt16.pushType(); bt16.size(btX, btY); bt16.position(hoffset(0), voffset(cellVspace)); bt16.name("16"); v.addElement(bt16); bt17.pushType(); bt17.size(btX, btY); bt17.position(hoffset(cellHspace), voffset(0)); bt17.name("17"); v.addElement(bt17); bt18.pushType(); bt18.size(btX, btY); bt18.position(hoffset(cellHspace), voffset(0)); bt18.name("18"); v.addElement(bt18); bt19.pushType(); bt19.size(btX, btY); bt19.position(hoffset(cellHspace), voffset(0)); bt19.name("19"); v.addElement(bt19); bt20.pushType(); bt20.size(btX, btY); bt20.position(hoffset(cellHspace), voffset(0)); bt20.name("20"); v.addElement(bt20); 4 => gHOffset; bt21.pushType(); bt21.size(btX, btY); bt21.position(hoffset(0), voffset(cellVspace)); bt21.name("21"); v.addElement(bt21); bt22.pushType(); bt22.size(btX, btY); bt22.position(hoffset(cellHspace), voffset(0)); bt22.name("22"); v.addElement(bt22); bt23.pushType(); bt23.size(btX, btY); bt23.position(hoffset(cellHspace), voffset(0)); bt23.name("23"); v.addElement(bt23); bt24.pushType(); bt24.size(btX, btY); bt24.position(hoffset(cellHspace), voffset(0)); bt24.name("24"); v.addElement(bt24); bt25.pushType(); bt25.size(btX, btY); bt25.position(hoffset(cellHspace), voffset(0)); bt25.name("25"); v.addElement(bt25); 4 => gHOffset; bt26.pushType(); bt26.size(btX, btY); bt26.position(hoffset(0), voffset(cellVspace)); bt26.name("26"); v.addElement(bt26); bt27.pushType(); bt27.size(btX, btY); bt27.position(hoffset(cellHspace), voffset(0)); bt27.name("27"); v.addElement(bt27); bt28.pushType(); bt28.size(btX, btY); bt28.position(hoffset(cellHspace), voffset(0)); bt28.name("28"); v.addElement(bt28); bt29.pushType(); bt29.size(btX, btY); bt29.position(hoffset(cellHspace), voffset(0)); bt29.name("29"); v.addElement(bt29); bt30.pushType(); bt30.size(btX, btY); bt30.position(hoffset(cellHspace), voffset(0)); bt30.name("30"); v.addElement(bt30); 4 => gHOffset; bt31.pushType(); bt31.size(btX, btY); bt31.position(hoffset(0), voffset(cellVspace)); bt31.name("31"); v.addElement(bt31); bt32.pushType(); bt32.size(btX, btY); bt32.position(hoffset(cellHspace), voffset(0)); bt32.name("32"); v.addElement(bt32); bt33.pushType(); bt33.size(btX, btY); bt33.position(hoffset(cellHspace), voffset(0)); bt33.name("33"); v.addElement(bt33); bt34.pushType(); bt34.size(btX, btY); bt34.position(hoffset(cellHspace), voffset(0)); bt34.name("34"); v.addElement(bt34); bt35.pushType(); bt35.size(btX, btY); bt35.position(hoffset(cellHspace), voffset(0)); bt35.name("35"); v.addElement(bt35); 4 => gHOffset; bt36.pushType(); bt36.size(btX, btY); bt36.position(hoffset(0), voffset(cellVspace)); bt36.name("36"); v.addElement(bt36); bt37.pushType(); bt37.size(btX, btY); bt37.position(hoffset(cellHspace), voffset(0)); bt37.name("37"); v.addElement(bt37); bt38.pushType(); bt38.size(btX, btY); bt38.position(hoffset(cellHspace), voffset(0)); bt38.name("38"); v.addElement(bt38); bt39.pushType(); bt39.size(btX, btY); bt39.position(hoffset(cellHspace), voffset(0)); bt39.name("39"); v.addElement(bt39); bt40.pushType(); bt40.size(btX, btY); bt40.position(hoffset(cellHspace), voffset(0)); bt40.name("40"); v.addElement(bt40); 4 => gHOffset; bt41.pushType(); bt41.size(btX, btY); bt41.position(hoffset(0), voffset(cellVspace)); bt41.name("41"); v.addElement(bt41); bt42.pushType(); bt42.size(btX, btY); bt42.position(hoffset(cellHspace), voffset(0)); bt42.name("42"); v.addElement(bt42); bt43.pushType(); bt43.size(btX, btY); bt43.position(hoffset(cellHspace), voffset(0)); bt43.name("43"); v.addElement(bt43); bt44.pushType(); bt44.size(btX, btY); bt44.position(hoffset(cellHspace), voffset(0)); bt44.name("44"); v.addElement(bt44); bt45.pushType(); bt45.size(btX, btY); bt45.position(hoffset(cellHspace), voffset(0)); bt45.name("45"); v.addElement(bt45); 4 => gHOffset; bt46.pushType(); bt46.size(btX, btY); bt46.position(hoffset(0), voffset(cellVspace)); bt46.name("46"); v.addElement(bt46); bt47.pushType(); bt47.size(btX, btY); bt47.position(hoffset(cellHspace), voffset(0)); bt47.name("47"); v.addElement(bt47); bt48.pushType(); bt48.size(btX, btY); bt48.position(hoffset(cellHspace), voffset(0)); bt48.name("48"); v.addElement(bt48); bt49.pushType(); bt49.size(btX, btY); bt49.position(hoffset(cellHspace), voffset(0)); bt49.name("49"); v.addElement(bt49); bt50.pushType(); bt50.size(btX, btY); bt50.position(hoffset(cellHspace), voffset(0)); bt50.name("50"); v.addElement(bt50); 4 => gHOffset; bt51.pushType(); bt51.size(btX, btY); bt51.position(hoffset(0), voffset(cellVspace)); bt51.name("51"); v.addElement(bt51); bt52.pushType(); bt52.size(btX, btY); bt52.position(hoffset(cellHspace), voffset(0)); bt52.name("52"); v.addElement(bt52); bt53.pushType(); bt53.size(btX, btY); bt53.position(hoffset(cellHspace), voffset(0)); bt53.name("53"); v.addElement(bt53); octaveDrop.toggleType(); octaveDrop.size(90, btY); octaveDrop.position(hoffset(cellHspace-75), voffset(60)); octaveDrop.name("8vb"); v.addElement(octaveDrop); /* octaveUp.toggleType(); octaveUp.size(90, btY); octaveUp.position(hoffset(cellHspace+20), voffset(0)); octaveUp.name("8ve"); v.addElement(octaveUp); */ twooctaveDrop.toggleType(); twooctaveDrop.size(90, btY); twooctaveDrop.position(hoffset(cellHspace+20), voffset(0)); twooctaveDrop.name("16vb"); v.addElement(twooctaveDrop); v.display(); // ========================================================================== // computer keyboard input via terminal (terminal only; ne marche pas dans "l'audicle petite" //KBHit kb; 120 => int tempo; 0 => int counter; // MIDI note constants 48 => int c3; 60 => int c4; 72 => int c5; 84 => int c6; 49 => int d3b; 61 => int d4b; 73 => int d5b; 85 => int d6b; 50 => int d3; 62 => int d4; 74 => int d5; 86 => int d6; 51 => int e3b; 63 => int e4b; 75 => int e5b; 87 => int e6b; 52 => int e3; 64 => int e4; 76 => int e5; 88 => int e6; 53 => int f3; 65 => int f4; 77 => int f5; 89 => int f6; 54 => int g3b; 66 => int g4b; 78 => int g5b; 90 => int g6b; 55 => int g3; 67 => int g4; 79 => int g5; 91 => int g6; 56 => int a3b; 68 => int a4b; 80 => int a5b; 92 => int a6b; 57 => int a3; 69 => int a4; 81 => int a5; 93 => int a6; 58 => int b3b; 70 => int b4b; 82 => int b5b; 94 => int b6b; 59 => int b3; 71 => int b4; 83 => int b5; 95 => int b6; // rest is music too 0 => int r; 1 => int t1; // whole 2 => int t2; // half 4 => int t4; // quarter 8 => int t8; // eighth 16 => int t16; // 16th 32 => int t32; // 32th 64 => int grace; // grace note // arbitrary values for dotted figures 3 => int t2d; // dotted half 5 => int t4d; // dotted quarter 9 => int t8d; // dotted eigth 10 => int twd; // dotted whole 99 => int x13; // exception for cell 13 (dotted-half tied to a sixteenth fun dur bpm2ms(float val) { return 480000::ms / val; } fun dur duration(int figure) { /// <<< figure >>>; if (figure == t2d ) return duration(t2) + duration(t4); else if (figure == twd) return duration(t1) + duration(t2); else if (figure == t4d) return duration(t4) + duration(t8); else if (figure == t8d) return duration(t8) + duration(t16); else if (figure == x13) return duration(t2d) + duration (t16); else if (figure == grace){ debug("duration", "figure==grace"); return bpm2ms((figure + Std.rand2f(-10., 10.)) * tempo);} else return bpm2ms(figure * tempo); } fun int setCount(int val) { val => counter; } fun int nextCount() { if(started>0) counter + 1 => counter; return counter; } fun int currCount() { return counter; } fun int lastCount() { if(counter!=0) counter-1 => counter; return counter; } class Cell { int number; int notes[][]; fun void set(int num) { num => number; }; fun void arraySet(int val[][]) { val @=> notes; } fun int getDur(int row, int cell) { return notes[row][cell]; } fun int cap(){ return notes.cap(); } fun int[] getNote(int i) { return notes[i]; } } Cell inC[53]; new Cell @=> Cell Cell1; Cell1.arraySet([ [c4, grace], [e4, t4], [c4, grace], [e4, t4], [c4, grace], [e4, t4] ] @=> int cell1[][]); Cell1 @=> inC[0]; new Cell @=> Cell Cell2; Cell2.arraySet([ [c4, grace], [e4,t8], [f4,t8], [e4,t4] ] @=> int cell2[][]); Cell2 @=> inC[1]; new Cell @=> Cell Cell3; Cell3.arraySet([ [r,t8], [e4,t8], [f4,t8], [e4,t8] ] @=> int cell3[][]); Cell3 @=> inC[2]; new Cell @=> Cell Cell4; Cell4.arraySet([ [r,t8],[e4,t8],[f4,t8],[g4,t8]] @=> int cell4[][]); Cell4 @=> inC[3]; new Cell @=> Cell Cell5; Cell5.arraySet([ [e4,t8],[f4,t8],[g4,t8],[r,t8]] @=> int cell5[][]); Cell5 @=> inC[4]; new Cell @=> Cell Cell6; //Cell6.arraySet([ [c5,t1],[c5,t1]] @=> int cell6[][]); Cell6.arraySet([ [c5,t1+t1]] @=> int cell6[][]); Cell6 @=> inC[5]; new Cell @=> Cell Cell7; Cell7.arraySet([ [r,t4], [r,t4], [r,t4], [r,t8], [c4,t16], [c4,t16], [c4,t16], [r,t8], [r,t4], [r,t4], [r,t4], [r,t4] ] @=> int cell7[][]); Cell7 @=> inC[6]; new Cell @=> Cell Cell8; //Cell8.arraySet([ [g4,twd], [f4, t1], [f4, t1] ] @=> int cell8[][]); Cell8.arraySet([ [g4,twd], [f4, t1+t1] ] @=> int cell8[][]); Cell8 @=> inC[7]; new Cell @=> Cell Cell9; Cell9.arraySet([ [b4,t16], [g4,t16], [r,t8], [r,t4], [r,t4], [r,t4]] @=> int cell9[][]); Cell9 @=> inC[8]; new Cell @=> Cell Cell10; Cell10.arraySet([ [b4,t16], [g4,t16]] @=> int cell10[][]); Cell10 @=> inC[9]; new Cell @=> Cell Cell11; Cell11.arraySet([ [f4,t16], [g4,t16], [b4,t16], [g4,t16],[b4,t16], [g4,t16] ] @=> int cell11[][]); Cell11 @=> inC[10]; new Cell @=> Cell Cell12; Cell12.arraySet([ [f4,t8], [g4,t8], [b4,t1], [c5,t4]] @=> int cell12[][]); Cell12 @=> inC[11]; new Cell @=> Cell Cell13; Cell13.arraySet([ [b4,t16], [g4,t8d], [g4,t16], [f4,t16], [g4,t8], [r,t8d], [g4,x13] ] @=> int cell13[][]); Cell13 @=> inC[12]; new Cell @=> Cell Cell14; Cell14.arraySet([ [c5,t1], [b4,t1], [g4,t1], [g4b,t1] ] @=> int cell14[][]); Cell14 @=> inC[13]; new Cell @=> Cell Cell15; Cell15.arraySet([ [g4,t16], [r,t8d], [r,t4], [r,t4] ] @=> int cell15[][]); Cell15 @=> inC[14]; new Cell @=> Cell Cell16; Cell16.arraySet([ [g4,t16], [b4,t16], [c5,t16],[b4,t16]] @=> int cell16[][]); Cell16 @=> inC[15]; new Cell @=> Cell Cell17; Cell17.arraySet([ [b4,t16], [c5,t16], [b4,t16], [c5,t16], [b4,t16], [r,t16] ] @=> int cell17[][]); Cell17 @=> inC[16]; new Cell @=> Cell Cell18; Cell18.arraySet([ [e4,t16], [g4b,t16], [e4,t16], [g4b,t16], [e4,t8d], [e4,t16] ] @=> int cell18[][]); Cell18 @=> inC[17]; new Cell @=> Cell Cell19; Cell19.arraySet([ [r, t4d], [g5,t4d] ] @=> int cell19[][]); Cell19 @=> inC[18]; new Cell @=> Cell Cell20; Cell20.arraySet([ [e4,t16], [g4b,t16], [e4,t16], [g4b,t16], [g3,t8d], [e4,t16], [g4b,t16], [e4,t16], [g4b,t16], [e4,t16] ] @=> int cell20[][]); Cell20 @=> inC[19]; new Cell @=> Cell Cell21; Cell21.arraySet([ [g4b,t2d] ] @=> int cell21[][]); Cell21 @=> inC[20]; new Cell @=> Cell Cell22; Cell22.arraySet([ [e4,t4d], [e4,t4d], [e4,t4d], [e4,t4d], [e4,t4d], [g4b,t4d], [g4,t4d], [a4,t4d], [b4,t8] ] @=> int cell22[][]); Cell22 @=> inC[21]; new Cell @=> Cell Cell23; Cell23.arraySet([ [e4,t8], [g4b,t4d], [g4b,t4d], [g4b,t4d], [g4b,t4d], [g4b,t4d], [g4,t4d], [a4,t4d], [b4,t4] ] @=> int cell23[][]); Cell23 @=> inC[22]; new Cell @=> Cell Cell24; Cell24.arraySet([ [e4,t8], [g4b,t8], [g4,t4d], [g4,t4d], [g4,t4d], [g4,t4d], [g4,t4d], [a4,t4d], [b4,t8] ] @=> int cell24[][]); Cell24 @=> inC[23]; new Cell @=> Cell Cell25; Cell25.arraySet([ [e4,t8], [g4b,t8], [g4,t8], [a4,t4d], [a4,t4d], [a4,t4d], [a4,t4d], [a4,t4d], [b4,t4d] ] @=> int cell25[][]); Cell25 @=> inC[24]; new Cell @=> Cell Cell26; Cell26.arraySet([ [e4,t8], [g4b,t8], [g4,t8], [a4,t8], [b4,t4d], [b4,t4d], [b4,t4d], [b4,t4d], [b4,t4d] ] @=> int cell26[][]); Cell26 @=> inC[25]; new Cell @=> Cell Cell27; Cell27.arraySet([ [e4,t16], [g4b,t16], [e4,t16], [g4b,t16], [g4, t8], [e4, t16], [g4, t16], [g4b,t16], [e4,t16], [g4b,t16], [e4,t16] ] @=> int cell27[][]); Cell27 @=> inC[26]; new Cell @=> Cell Cell28; Cell28.arraySet([ [e4,t16], [g4b,t16], [e4,t16], [g4b,t16], [e4, t8d], [e4, t16] ] @=> int cell28[][]); Cell28 @=> inC[27]; new Cell @=> Cell Cell29; Cell29.arraySet([ [e4,t2d], [g4,t2d], [c5,t2d] ] @=> int cell29[][]); Cell29 @=> inC[28]; new Cell @=> Cell Cell30; Cell30.arraySet([ [c5,twd] ] @=> int cell30[][]); Cell30 @=> inC[29]; new Cell @=> Cell Cell31; Cell31.arraySet([ [g4,t16], [f4,t16], [g4,t16], [b4,t16], [g4,t16], [b4,t16] ] @=> int cell31[][]); Cell31 @=> inC[30]; new Cell @=> Cell Cell32; Cell32.arraySet([ [f4,t16], [g4,t16], [f4,t16], [g4,t16], [b4,t16], [f4, x13], [g4, t4d] ] @=> int cell32[][]); Cell32 @=> inC[31]; new Cell @=> Cell Cell33; Cell33.arraySet([ [g4,t16], [f4,t16], [r,t8] ] @=> int cell33[][]); Cell33 @=> inC[32]; new Cell @=> Cell Cell34; Cell34.arraySet([ [g4,t16], [f4,t16] ] @=> int cell34[][]); Cell34 @=> inC[33]; new Cell @=> Cell Cell35; Cell35.arraySet([ [f4,t16], [g4,t16], [b4,t16], [g4,t16], [b4,t16], [g4,t16], [b4,t16], [g4,t16], [b4,t16], [g4,t16], [r, t8], [r, t4], [r, t4], [r, t4], [b4b, t4], [g5, t2d], [a5, t8], [g5, t4], [b5, t8], [a5, t4d], [g5, t8], [e5, t2d], [g5, t8], [g5b, t8+t2d], [r, t4], [r, t4], [r, t8], [e5, t8+t2], [f5, twd] ] @=> int cell35[][]); Cell35 @=> inC[34]; new Cell @=> Cell Cell36; Cell36.arraySet([ [f4,t16], [g4,t16], [b4,t16], [g4,t16], [b4,t16], [g4,t16] ] @=> int cell36[][]); Cell36 @=> inC[35]; new Cell @=> Cell Cell37; Cell37.arraySet([ [f4,t16], [g4,t16] ] @=> int cell37[][]); Cell37 @=> inC[36]; new Cell @=> Cell Cell38; Cell38.arraySet([ [f4,t16], [g4,t16], [b4,t16] ] @=> int cell38[][]); Cell38 @=> inC[37]; new Cell @=> Cell Cell39; Cell39.arraySet([ [b4,t16], [g4, t16], [f4, t16], [g4, t16], [b4, t16], [c5, t16] ] @=> int cell39[][]); Cell39 @=> inC[38]; new Cell @=> Cell Cell40; Cell40.arraySet([ [b4,t16], [f4,t16] ] @=> int cell40[][]); Cell40 @=> inC[39]; new Cell @=> Cell Cell41; Cell41.arraySet([ [b4,t16], [g4,t16] ] @=> int cell41[][]); Cell41 @=> inC[40]; new Cell @=> Cell Cell42; Cell42.arraySet([ [c5, t1], [b4, t1], [a4, t1], [c5, t1] ] @=> int cell42[][]); Cell42 @=> inC[41]; new Cell @=> Cell Cell43; Cell43.arraySet([ [f5, t16], [e5, t16], [f5, t16], [e5, t16], [e5, t8], [e5, t8], [e5, t8], [f5, t16], [e5, t16] ] @=> int cell43[][]); Cell43 @=> inC[42]; new Cell @=> Cell Cell44; Cell44.arraySet([ [f5, t8], [e5, t4], [e5, t8], [c5, t4] ] @=> int cell44[][]); Cell44 @=> inC[43]; new Cell @=> Cell Cell45; Cell45.arraySet([ [d5,t4], [d5,t4], [g4,t4] ] @=> int cell45[][]); Cell45 @=> inC[44]; new Cell @=> Cell Cell46; Cell46.arraySet([ [g4, t16], [d5, t16], [e5, t16], [d5, t16], [r, t8], [g4, t8], [r, t8], [g4, t8], [r, t8], [g4, t8], [g4, t16], [d5, t16], [e5, t16], [d5, t16] ] @=> int cell46[][]); Cell46 @=> inC[45]; new Cell @=> Cell Cell47; Cell47.arraySet([ [d5, t16], [e5, t16], [d5, t8] ] @=> int cell47[][]); Cell47 @=> inC[46]; new Cell @=> Cell Cell48; Cell48.arraySet([ [g4, twd], [g4, t1], [f4, t1+t4] ] @=> int cell48[][]); Cell48 @=> inC[47]; new Cell @=> Cell Cell49; Cell49.arraySet([ [f4, t16], [g4, t16], [b4b, t16], [g4, t16], [b4b, t16], [g4, t16] ] @=> int cell49[][]); Cell49 @=> inC[48]; new Cell @=> Cell Cell50; Cell50.arraySet([ [f4,t16], [g4, t16] ] @=> int cell50[][]); Cell50 @=> inC[49]; new Cell @=> Cell Cell51; Cell51.arraySet([ [f4,t16], [g4, t16], [b4b, t16] ] @=> int cell51[][]); Cell51 @=> inC[50]; new Cell @=> Cell Cell52; Cell52.arraySet([ [g4, t16], [b4b,t16] ] @=> int cell52[][]); Cell52 @=> inC[51]; new Cell @=> Cell Cell53; Cell53.arraySet([ [b4b,t16], [g4, t16] ] @=> int cell53[][]); Cell53 @=> inC[52]; 0 => int msg_prevCell; 0 => int msg_nextCell; 0 => int msg_playCell; // Play a fragment Event starting; Event finished; fun void playCell(StkInstrument m, Cell voice) { // to mark first play... debug("playCell", "start"); if(started==0) 1=>started; if(tempo==0) 120=>tempo; 1 => cellPlaying; currentCell.name( "[" + (currCount()+1) + "]" ); starting.broadcast(); debug("playCell", "after broadcast"); 0=>int midiPitch; for( 0 => int i; i < voice.cap(); i++) { debug("playCell", "in for loop"); voice.getDur(i, 0) => midiPitch; if ( midiPitch > 0 ) { if(g_octaveDrop==1) midiPitch-12=>midiPitch; else if(g_octaveDrop==2) midiPitch-24=>midiPitch; Std.mtof( midiPitch) => m.freq; debug("playCell", "playing notes"); 1.0 => m.noteOn; } debug("playCell", "before get duration"); duration(voice.getDur(i, 1)) => now; debug("playCell", "after get duration"); } 0 => cellPlaying; finished.broadcast(); } // MAUI SECTION ================================================== function void controlGain() { while( true ) { volume_slider => now; volume_slider.value() => master.gain; } } Event loopOn; Event loopOff; Event nextCell; Event prevCell; function void controlLoop() { while(true) { debug("controlLoop", "start"); loop => now; loopOn.broadcast(); 1 => loopValue; spork ~ looper(); loop => now; loopOff.broadcast(); 0 => button_loop; 0 => loopValue; } } fun void looper() { debug("looper", "start"); while (loopValue == 1) { // if(cellPlaying>0) //&& (msg_nextCell+msg_prevCell>0)) // finished => now; // else pulse => now; // <<< "looper::msg_nextCell: ", msg_nextCell >>>; // if next cell is pressed during the loop... if(msg_nextCell==1) { 0 => msg_nextCell; if(cellPlaying>0) finished => now; // pulse => now; spork ~ playCell(currentInstrument, inC[nextCount()]); } else if(msg_prevCell==1) { 0 => msg_prevCell; if(cellPlaying>0) finished => now; // pulse => now; spork ~ playCell(currentInstrument, inC[lastCount()]); } else if(msg_playCell==1) { 0 => msg_playCell; debug("looper", "if(msg_playCell==1)"); if(cellPlaying>0) finished => now; // pulse => now; spork ~ playCell(currentInstrument, inC[currCount()]); } else if(button_loop==1){ if(cellPlaying>0) finished => now; // pulse => now; spork ~ playCell(currentInstrument, inC[currCount()]); } } } function void controlNext() { while( true ) { next => now; // if(loopValue==1) 1 => button_loop; // <<<"controlNext::cellPlaying: ", cellPlaying>>>; if(loopValue == 0) { // <<<"controlNext::cellPlaying: ", cellPlaying>>>; if(cellPlaying >0) finished => now; // else pulse => now; spork ~ playCell(currentInstrument, inC[nextCount()]); } else { 1 => msg_nextCell; // <<<"controlNext::msg_nextCell: ", msg_nextCell>>>; } next => now; } } function void controlLast() { while( true ) { prev => now; 1 => button_loop; if(loopValue == 0) { if(cellPlaying >0) finished => now; pulse => now; spork ~ playCell(currentInstrument, inC[lastCount()]); } else { 1 => msg_prevCell; } prev => now; } } // to play a cell, multiple conditions must be met: // 1) one of the buttons (play, next, prev, cell#) must be pressed // 2) no other cell must be playing // 3) a sync pulse must be received // 1) each button fires an event which is received by that button's pre-sporked fn // 2) if this is the very first cell play in the piece, wait for event "pulse" then spork playCell // 3) if this isn't the first play, // // 2) that fn sporks a shred "freeCell()" which if the "cellPlaying" gvar is > 0, waits for a finished event to trigger // 3) freeCell calls playCell function void controlPlay() { while( true ) { debug("controlPlay", "start"); playpause => now; debug("controlPlay", "after playpause"); 1 => button_loop; if(loopValue == 0) { debug("controlPlay", "if loopvalue=0"); if(cellPlaying >0) finished => now; debug("controlPlay", "after finished=>now"); pulse => now; spork ~ playCell(currentInstrument, inC[currCount()]); } else { 1 => msg_playCell; } playpause => now; } } function void freeCells() { while(true) { starting => now; 1 => cellPlaying; finished => now; 0 => cellPlaying; } } fun void playLight() { while(true) { starting => now; 60::ms => now; b.light(); finished => now; b.unlight(); } } int x; int y; fun void lighter(){ while(true) { pulse => now; a.light(); 120::ms => now; a.unlight(); } } // receiver fun void clock() { // create our OSC receiver OscRecv recv; // use port 6449 6449 => recv.port; // start listening (launch thread) recv.listen(); // create an address in the receiver, store in new variable recv.event( "/slork/synch/clock, i i" ) @=> OscEvent oe; // count 0 => int count; // infinite event loop while ( true ) { // wait for event to arrive oe => now; // grab the next message from the queue. while( oe.nextMsg() != 0 ) { // get x and y oe.getInt() => x; oe.getInt() => y; x => tempo; pulse.broadcast(); // the clock event signals the next ~ playCell } } } fun void playButtons(int val) { 1 => button_loop; setCount(val-1); if(loopValue == 0) { if(cellPlaying >0) finished => now; pulse => now; spork ~ playCell(currentInstrument, inC[currCount()]); } else { 1 => msg_playCell; } } fun void button1() { while(true){ bt1 => now; playButtons(1); bt1 =>now; } } fun void button2() { while(true){ bt2 => now; playButtons(2); bt2 =>now; } } fun void button3() { while(true){ bt3 => now; playButtons(3); bt3 =>now; } } fun void button4() { while(true){ bt4 => now; playButtons(4); bt4 =>now; } } fun void button5() { while(true){ bt5 => now; playButtons(5); bt5 =>now; } } fun void button6() { while(true){ bt6 => now; playButtons(6); bt6 =>now; } } fun void button7() { while(true){ bt7 => now; playButtons(7); bt7 =>now; } } fun void button8() { while(true){ bt8 => now; playButtons(8); bt8 =>now; } } fun void button9() { while(true){ bt9 => now; playButtons(9); bt9 =>now; } } fun void button10() { while(true){ bt10 => now; playButtons(10); bt10 =>now; } } fun void button11() { while(true){ bt11 => now; playButtons(11); bt11 =>now; } } fun void button12() { while(true){ bt12 => now; playButtons(12); bt12 =>now; } } fun void button13() { while(true){ bt13 => now; playButtons(13); bt13 =>now; } } fun void button14() { while(true){ bt14 => now; playButtons(14); bt14 =>now; } } fun void button15() { while(true){ bt15 => now; playButtons(15); bt15 =>now; } } fun void button16() { while(true){ bt16 => now; playButtons(16); bt16 =>now; } } fun void button17() { while(true){ bt17 => now; playButtons(17); bt17 =>now; } } fun void button18() { while(true){ bt18 => now; playButtons(18); bt18 =>now; } } fun void button19() { while(true){ bt19 => now; playButtons(19); bt19 =>now; } } fun void button20() { while(true){ bt20 => now; playButtons(20); bt20 =>now; } } fun void button21() { while(true){ bt21 => now; playButtons(21); bt21 =>now; } } fun void button22() { while(true){ bt22 => now; playButtons(22); bt22 =>now; } } fun void button23() { while(true){ bt23 => now; playButtons(23); bt23 =>now; } } fun void button24() { while(true){ bt24 => now; playButtons(24); bt24 =>now; } } fun void button25() { while(true){ bt25 => now; playButtons(25); bt25 =>now; } } fun void button26() { while(true){ bt26 => now; playButtons(26); bt26 =>now; } } fun void button27() { while(true){ bt27 => now; playButtons(27); bt27 =>now; } } fun void button28() { while(true){ bt28 => now; playButtons(28); bt28 =>now; } } fun void button29() { while(true){ bt29 => now; playButtons(29); bt29 =>now; } } fun void button30() { while(true){ bt30 => now; playButtons(30); bt30 =>now; } } fun void button31() { while(true){ bt31 => now; playButtons(31); bt31 =>now; } } fun void button32() { while(true){ bt32 => now; playButtons(32); bt32 =>now; } } fun void button33() { while(true){ bt33 => now; playButtons(33); bt33 =>now; } } fun void button34() { while(true){ bt34 => now; playButtons(34); bt34 =>now; } } fun void button35() { while(true){ bt35 => now; playButtons(35); bt35 =>now; } } fun void button36() { while(true){ bt36 => now; playButtons(36); bt36 =>now; } } fun void button37() { while(true){ bt37 => now; playButtons(37); bt37 =>now; } } fun void button38() { while(true){ bt38 => now; playButtons(38); bt38 =>now; } } fun void button39() { while(true){ bt39 => now; playButtons(39); bt39 =>now; } } fun void button40() { while(true){ bt40 => now; playButtons(40); bt40 =>now; } } fun void button41() { while(true){ bt41 => now; playButtons(41); bt41 =>now; } } fun void button42() { while(true){ bt42 => now; playButtons(42); bt42 =>now; } } fun void button43() { while(true){ bt43 => now; playButtons(43); bt43 =>now; } } fun void button44() { while(true){ bt44 => now; playButtons(44); bt44 =>now; } } fun void button45() { while(true){ bt45 => now; playButtons(45); bt45 =>now; } } fun void button46() { while(true){ bt46 => now; playButtons(46); bt46 =>now; } } fun void button47() { while(true){ bt47 => now; playButtons(47); bt47 =>now; } } fun void button48() { while(true){ bt48 => now; playButtons(48); bt48 =>now; } } fun void button49() { while(true){ bt49 => now; playButtons(49); bt49 =>now; } } fun void button50() { while(true){ bt50 => now; playButtons(50); bt50 =>now; } } fun void button51() { while(true){ bt51 => now; playButtons(51); bt51 =>now; } } fun void button52() { while(true){ bt52 => now; playButtons(52); bt52 =>now; } } fun void button53() { while(true){ bt53 => now; playButtons(53); bt53 =>now; } } fun void octaveDropper() { while(true){ <<<"test">>>; octaveDrop => now; 1 => g_octaveDrop; // twooctaveDrop.pushType(); octaveDrop =>now; 0 => g_octaveDrop; // twooctaveDrop.toggleType(); } } /* fun void octaveUpper() { while(true){ octaveUp => now; 2 => g_octaveDrop; // octaveDrop.pushType(); octaveUp =>now; 0 => g_octaveDrop; // octaveDrop.toggleType(); } } */ fun void twooctaveDropper() { while(true){ twooctaveDrop => now; 2 => g_octaveDrop; // octaveDrop.pushType(); twooctaveDrop =>now; 0 => g_octaveDrop; // octaveDrop.toggleType(); } } spork ~ clock(); spork ~ lighter(); spork ~ controlGain(); spork ~ playLight(); spork ~ controlPlay(); spork ~ controlLoop(); spork ~ controlNext(); spork ~ controlLast(); spork ~ freeCells(); spork ~ octaveDropper(); spork ~ twooctaveDropper(); //spork ~ octaveUpper(); spork ~ button1(); spork ~ button2(); spork ~ button3(); spork ~ button4(); spork ~ button5(); spork ~ button6(); spork ~ button7(); spork ~ button8(); spork ~ button9(); spork ~ button10(); spork ~ button11(); spork ~ button12(); spork ~ button13(); spork ~ button14(); spork ~ button15(); spork ~ button16(); spork ~ button17(); spork ~ button18(); spork ~ button19(); spork ~ button20(); spork ~ button21(); spork ~ button22(); spork ~ button23(); spork ~ button24(); spork ~ button25(); spork ~ button26(); spork ~ button27(); spork ~ button28(); spork ~ button29(); spork ~ button30(); spork ~ button31(); spork ~ button32(); spork ~ button33(); spork ~ button34(); spork ~ button35(); spork ~ button36(); spork ~ button37(); spork ~ button38(); spork ~ button39(); spork ~ button40(); spork ~ button41(); spork ~ button42(); spork ~ button43(); spork ~ button44(); spork ~ button45(); spork ~ button46(); spork ~ button47(); spork ~ button48(); spork ~ button49(); spork ~ button50(); spork ~ button51(); spork ~ button52(); spork ~ button53(); 1::day => now;