From 987174db31cedf0a8f03f2389559d4bd6979b13c Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 6 Sep 2024 22:31:37 +0200 Subject: [PATCH] init --- MIDI_synth_1.ck | 67 ++++++++++++++++++++++++++++++++++ MIDI_synth_2.ck | 97 +++++++++++++++++++++++++++++++++++++++++++++++++ MidiSynth_1.ck | 28 ++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 MIDI_synth_1.ck create mode 100644 MIDI_synth_2.ck create mode 100644 MidiSynth_1.ck diff --git a/MIDI_synth_1.ck b/MIDI_synth_1.ck new file mode 100644 index 0000000..0b6ea4b --- /dev/null +++ b/MIDI_synth_1.ck @@ -0,0 +1,67 @@ +4 => int device; +13 => int ctlNrFreq; +16 => int ctlNrVol; +9 => int ctlNrAux1; +10 => int ctlNrAux2; + +64 => int voicesNr; + +// Midi +MidiIn min; +MidiMsg msg; +if( !min.open( device ) ) { + me.exit(); +} +<<< "MIDI device:", min.num(), " -> ", min.name() >>>; + +//UGENs +SinOsc s[voicesNr]; +for(0 => int i; i < voicesNr-2; i++) { + s[i] => s[i+1]; + s[i].sync(2); +} +s[voicesNr-3] => dac; + + +//params +0. => float aux1; +0. => float aux2; +0. => float freq; +0.1 => float gain; + +while( true ) +{ + min => now; + + while( min.recv(msg) ) { + <<< msg.data1, msg.data2, msg.data3 >>>; + } + + + if(msg.data2 == ctlNrFreq) { + msg.data3 => freq; + } + if(msg.data2 == ctlNrVol) { + msg.data3/127. => gain; + } + if(msg.data2 == ctlNrAux1) { + msg.data3/127. => aux1; + } + if(msg.data2 == ctlNrAux2) { + msg.data3/127. => aux2; + } + + for(0 => int i; i < voicesNr; i++) { + voice(i); + } + +} + +fun void voice(int i) { + 1. / voicesNr => s[i].gain; + 50 + i => s[i].freq; + freq * (i+aux1) => s[i].sfreq; + gain => s[i].gain; + +} + diff --git a/MIDI_synth_2.ck b/MIDI_synth_2.ck new file mode 100644 index 0000000..c9e29ff --- /dev/null +++ b/MIDI_synth_2.ck @@ -0,0 +1,97 @@ +4 => int device; +13 => int ctlNrFreq; +16 => int ctlNrVol; +12 => int ctlNrVoiceNr; +9 => int ctlNrAux1; +10 => int ctlNrAux2; + +64 => int voicesMax; +1 => int voicesNr; + +// Midi +MidiIn min; +MidiMsg msg; +if( !min.open( device ) ) { + me.exit(); +} +<<< "MIDI device:", min.num(), " -> ", min.name() >>>; + +//UGENs +SinOsc s[voicesMax]; +UGen sum; +sum => dac; + +//params +0. => float freq; +0.7 => float gain; +0.2 => float voicesRaw; +0. => float aux1; +0. => float aux2; + + +1 => int synthInvalidated; +1 => int patchInvalidated; +while( true ) { + //Patch + if(patchInvalidated) { + <<< "voices: " + voicesNr >>>; + setupOscPatch(voicesRaw); + 0 => patchInvalidated; + } + //Sythesis + if(synthInvalidated == 1) { + <<< freq,aux1,aux2,gain >>>; + + for(0 => int i; i < voicesNr; i++) { + voice(i); + } + 0 => synthInvalidated; + } + min => now; + //Parsing + min.recv(msg); + // <<< msg.data1, msg.data2, msg.data3 >>>; + + if(msg.data2 == ctlNrVoiceNr) { + 1 => patchInvalidated; + 1 => synthInvalidated; + msg.data3/127. => voicesRaw; + } + if(msg.data2 == ctlNrFreq) { + 1 => synthInvalidated; + msg.data3 => freq; + } + if(msg.data2 == ctlNrVol) { + 1 => synthInvalidated; + msg.data3/127. => gain; + } + if(msg.data2 == ctlNrAux1) { + 1 => synthInvalidated; + msg.data3/127. => aux1; + } + if(msg.data2 == ctlNrAux2) { + 1 => synthInvalidated; + msg.data3/127. => aux2; + } + +} + +fun void voice(int i) { + 50 + freq +i => s[i].sfreq; + i * (aux1/voicesNr+1) => float phase; + phase => s[i].phase; + gain => s[i].gain; +} + +fun void setupOscPatch(float pVoicesRaw) { + + Math.max(1.,Math.floor(voicesMax * pVoicesRaw)) $ int => voicesNr; + for(0 => int i; i < voicesMax; i++) { + s[i] =< sum; + } + for(0 => int i; i < voicesNr; i++) { + s[i] => sum; + } + 1./voicesNr => sum.gain; +} + diff --git a/MidiSynth_1.ck b/MidiSynth_1.ck new file mode 100644 index 0000000..8051339 --- /dev/null +++ b/MidiSynth_1.ck @@ -0,0 +1,28 @@ +4 => int device; + +MidiIn min; +MidiMsg msg; + +SinOsc s => dac; + + +if( !min.open( device ) ) { + me.exit(); +} +<<< "MIDI device:", min.num(), " -> ", min.name() >>>; + +// infinite time-loop +while( true ) +{ + min => now; + + while( min.recv(msg) ) + { + <<< msg.data1, msg.data2, msg.data3 >>>; + } + 13 => int ctlNrFreq; + + if(msg.data2 == 13) { + msg.data3 => s.freq; + } +}