Browse files

lot of news, added seqpanel, shortcut, samplelib in progress

  • Loading branch information...
1 parent eed7da6 commit 89ccb7c1d5ad72821dae277f892e9814e3a7ebd0 @grirgz committed Sep 28, 2011
Showing with 720 additions and 0 deletions.
  1. +251 −0 live6.sc
  2. +139 −0 samplelib.sc
  3. +330 −0 seqpanel.sc
View
251 live6.sc
@@ -0,0 +1,251 @@
+s.boot;
+
+
+
+(
+s.waitForBoot({
+
+"/home/ggz/code/sc/seco/seco.sc".loadDocument;
+~seq = ~mk_sequencer.value;
+~seq.test_player(\BigKick);
+
+});
+
+)
+~seq.current_test_player.as_event
+(
+s.waitForBoot({
+"/home/ggz/code/sc/seco/seco.sc".loadDocument;
+
+~synthlib = [
+ \sinadsr,
+ \vowel,
+ \kickTrig1,
+ \snTrig1,
+ \boom1,
+ \KSpluck,
+ \KSpluck2,
+ \KSpluck3,
+ \hihat
+].collect({ arg i; i -> i });
+
+~seq = ~mk_sequencer.value;
+~seq.load_patlib( ~synthlib );
+~seq.make_gui;
+
+});
+)
+
+(
+~seq.save_project("projperc2");
+~seq.load_project("projperc2");
+
+
+)
+
+(
+SynthDef(\formant, { arg out=0, amp=0.1, gate=1, freq=200, formfreq=300, bw=10;
+
+var ou;
+ou = Formant.ar(freq, formfreq, bw);
+ou = ou * Linen.kr(gate, doneAction:2);
+Out.ar(out, ou*amp);
+
+
+}, metadata:(specs:(
+ formfreq: \widefreq.asSpec,
+ bw: \widefreq.asSpec
+))).add;
+
+SynthDef(\formant2, { arg out=0, amp=0.1, gate=1, freq=200, formfreq=300, bandw=10, rq=0.1;
+
+ var ou, ou2;
+ ou = WhiteNoise.ar(1);
+ ou = Mix.fill(4, { arg num;
+ var stack=2;
+ var lou = ou;
+ num = num+1;
+ stack.do ({ arg i;
+ lou = BPF.ar(lou, freq*num, rq);
+ });
+ lou;
+ });
+ ou = ou * Linen.kr(gate, doneAction:2) * 10;
+ Out.ar(out, ou*amp);
+}, metadata:(specs:(
+ formfreq: \freq.asSpec,
+ bandw: \freq.asSpec
+))).add;
+
+SynthDef(\saw, { arg out=0, amp=0.1, gate=1, freq=200, formfreq=300, bw=10;
+
+var ou;
+ou = Saw.ar(freq);
+ou = ou * Linen.kr(gate, doneAction:2);
+Out.ar(out, ou*amp);
+
+
+}).add;
+
+
+SynthDef(\vowel, { arg out=0, amp=0.1, gate=1, freq=200, rqfreq=100, rqoffset=10;
+var env, env2, envf, enva, ou, ou2;
+env = ~make_adsr.(\adsr);
+env2 = ~make_adsr.(\adsr_vowel);
+envf = EnvGen.kr(env2, gate);
+enva = EnvGen.kr(env, gate,doneAction:2);
+ou = Formants.ar(freq, Vowel(\i, \bass).blend(Vowel(\o, \bass), envf + LFNoise0.kr([5,5.1],mul:0.1,add:1).lag(0.1))) ;
+ou = PinkNoise.ar(1)*0.5 + ou;
+ou2 = BPF.ar(ou, freq+LFNoise0.kr([1.12,5.2],1,20*enva).lag(0.1), SinOsc.kr(rqfreq*enva+rqoffset,0,1,4.1))*5;
+ou = Klank.ar(`[[1.1],[0.1],[0.5]],ou,700) + ou2;
+ou = ou*enva*amp;
+Out.ar(out, ou);
+
+}).store;
+
+SynthDef(\sinadsr, {
+ arg out=0, amp=0.1, gate=1, freq=440;
+ var ou;
+ var env, envctl;
+
+ env = Env.adsr(0.02, 0.2, 0.25, 0.1, 1, -4);
+ //env = Env.newClear(6);
+
+ envctl = Control.names([\adsr]).kr( env.asArray );
+ ou = SinOsc.ar( freq);
+ ou = ou * EnvGen.kr(envctl, gate, doneAction:2);
+ Out.ar(out, ou * amp)
+}).store;
+
+SynthDef("kickTrig1", { arg levK=1, t_trig=0, sustain=0.125, f1=36.7, f2=73.4, amp=0.1, out=0;
+ var kEnv, ou;
+ var kickEnv;
+ kickEnv = Env.linen(0.001, 1.9, 0.099, 1);
+ kEnv=EnvGen.ar(kickEnv,1, doneAction:2, timeScale: sustain, levelScale: levK);
+ ou =Pan2.ar(Decay2.kr(t_trig, 0.005, 0.45,
+ FSinOsc.ar(f1, 0.4)+FSinOsc.ar(f2, 0.2)),0);
+
+ Out.ar(out, ou * kEnv * amp);
+}).store;
+SynthDef("snTrig1", { arg levSn=1, t_trig=0, sustain=0.125, panPos=0, amp=0.1,
+ out=0;
+ var snEnv, ou;
+ var snareEnv;
+ snareEnv = Env.linen(0.001, 1.9, 0.099, 1);
+ snEnv=EnvGen.ar(snareEnv,1, doneAction:2, timeScale: sustain, levelScale: levSn);
+ ou =Pan2.ar(Decay2.kr(t_trig, 0.005, 0.25, FSinOsc.ar(38.midicps, 0.3)+ BrownNoise.ar(0.4)),panPos);
+
+ Out.ar(out, ou*snEnv * amp);
+}).store;
+SynthDef("hihat", { arg out=0, amp=0.1, sustain=0.5, freq=440, noise=0.5,
+ at=0.001, rq=1.9;
+ var ou;
+ ou = WhiteNoise.ar(noise);
+ ou = ou * EnvGen.kr(Env.perc(at, sustain),doneAction:2);
+ ou = Resonz.ar(ou, freq, rq);
+
+ Out.ar(out, ou*amp);
+}).store;
+
+
+
+SynthDef("boom1", {
+ arg out=0, t_trig=1, attack=0.005, release=1.25, noise=1, f_base=70,
+ mod=4, range=300, carrier=400, amp=0.1;
+
+ d = Decay2.kr(t_trig, attack, release, BrownNoise.ar(noise)
+ + SinOsc.ar(f_base)
+ + SinOsc.ar(SinOsc.kr(mod,1.0)*range+carrier)
+ );
+ DetectSilence.ar(in: d, amp: 0.001, time: 0.1, doneAction: 2);
+ Out.ar(out,d*amp)
+
+}).store;
+
+SynthDef("perc1", {
+ arg out=0, attack=0.005, release=1.25, lpf=50, bpf=100, bprq=0.1,
+ ratio=4, range=300, carrier=400, amp=0.1;
+ var mid, ou, env;
+
+ mid = SinOsc.ar(SinOsc.ar(carrier*ratio)*range+carrier);
+ mid = BPF.ar(mid, bpf, bprq);
+
+ ou = Klang.ar( `[[50,86,93,136,182],nil,nil] );
+ ou = LPF.ar(ou, lpf);
+ ou = mid + ou;
+
+ env = EnvGen.kr(Env.perc(attack, release), doneAction:2);
+ ou = ou * env * amp;
+
+ Out.ar(out,ou)
+
+}).store;
+
+SynthDef("snare1", {
+ arg out=0, attack=0.005, release=1.25, relratio=0.5, amp=0.1;
+ var mid, ou, ou2, env1, env2;
+
+ ou = LFTri.ar(111);
+ ou = FreqShift.ar(ou, [175, 224]).sum;
+ env1 = EnvGen.ar(Env.perc(attack, release), doneAction:2);
+
+ env2 = EnvGen.ar(Env.perc(attack, release*relratio));
+ ou2 = SinOsc.ar([330,180]).sum*env2;
+
+ ou = ou + ou2;
+ ou = ou * env1 * amp;
+
+
+ Out.ar(out,ou.dup)
+
+}).store;
+
+
+
+SynthDef("KSpluck", { arg freq = 200, delayDecay = 1.0, attack=0.0001, release=0.001, amp=0.1, out=0;
+ var burstEnv, att = attack, dec = release;
+ var signalOut, delayTime;
+ delayTime = [freq, freq * 2].reciprocal;
+ burstEnv = EnvGen.kr(Env.perc(att, dec));
+ signalOut = PinkNoise.ar(burstEnv);
+ signalOut = CombL.ar(signalOut, delayTime, delayTime, delayDecay, add: signalOut);
+ DetectSilence.ar(signalOut, doneAction:2);
+ Out.ar(out, signalOut*amp)
+}).store;
+
+SynthDef("KSpluck3", { arg freq = 200, delayDecay = 1.0, attack=0.1, release=0.1, amp=0.1, out=0;
+ var burstEnv, att = attack, dec = release;
+ var signalOut, delayTime;
+ delayTime = [freq, freq * 2].reciprocal;
+ burstEnv = EnvGen.kr(Env.perc(att, dec));
+ signalOut = PinkNoise.ar(10);
+ signalOut = CombL.ar(signalOut, delayTime, delayTime, delayDecay, add: signalOut);
+ signalOut = signalOut * burstEnv;
+ signalOut = signalOut * amp * 0.1;
+ DetectSilence.ar(signalOut, doneAction:2);
+ Out.ar([0,1], signalOut)
+}).store;
+
+SynthDef("KSpluck2", { arg freq = 200, noise=10, bpratio=0.9, rq=0.1, delayDecay = 1.0, attack=0.1, release=0.1, amp=0.1, out=0;
+ var burstEnv, att = attack, dec = release;
+ var signalOut, delayTime;
+ delayTime = [freq, freq * 2].reciprocal;
+ burstEnv = EnvGen.kr(Env.perc(att, dec));
+ signalOut = WhiteNoise.ar(noise);
+ signalOut = BPF.ar(signalOut, freq*bpratio, rq);
+ signalOut = CombL.ar(signalOut, delayTime, delayTime, [delayDecay, delayDecay*1.0.rand], add: signalOut);
+ signalOut = signalOut * burstEnv;
+ signalOut = signalOut * amp * 0.01;
+ DetectSilence.ar(signalOut, doneAction:2);
+ Out.ar(out, signalOut.dup)
+}).store;
+
+
+)
+(
+~btl_cells = GUI.hLayoutView.new(Window.new, Rect(0,0,100,100));
+~bt = Button.new(~btl_cells)
+~btl_cells.pad
+~btl_cells.jinsets;
+)
+nil.value = 4
View
139 samplelib.sc
@@ -0,0 +1,139 @@
+
+(
+~make_view_responder = { arg parent, model, message_responders;
+ var controller;
+
+ controller = SimpleController(model);
+
+ Dictionary.newFrom(message_responders).keysValuesDo { arg key, val;
+ controller.put(key, val)
+ };
+
+ parent.onClose = parent.onClose.addFunc { controller.remove };
+
+ model.refresh()
+};
+
+~make_sample_cell = { arg parent, label;
+ var bt;
+
+ bt = GUI.button.new(parent, Rect(50,50,200,30));
+ bt.states = [
+ [ label, Color.black, Color.white],
+ ];
+ bt.value = 0;
+
+};
+
+~samplelib_view = { arg parent, controller;
+
+ var sl_layout, ps_col_layout, curbank, address;
+ var width = 1350;
+
+ sl_layout = GUI.hLayoutView.new(parent, Rect(0,0,width,60*6));
+
+ //parent.view.background = ~editplayer_color_scheme.background;
+ ~make_view_responder.(sl_layout, controller, (
+
+ redraw: {
+ controller.model.samplelist.clump(4).clump(8)[controller.model.bank].do { arg col;
+ ps_col_layout = GUI.vLayoutView.new(sl_layout, Rect(0,0,(160),60*6));
+ ps_col_layout.background = ~editplayer_color_scheme.control;
+
+ col.do { arg label;
+ ~make_sample_cell.(ps_col_layout, label);
+ };
+ }
+ }
+ ))
+};
+
+
+
+~make_samplelib = { arg main;
+
+ var obj;
+
+ obj = (
+
+ model: (
+ samplelist: "sounds/default.wav"!50,
+ bank: 0
+ ),
+
+ kb_handler: Dictionary.new,
+
+ refresh: { arg self;
+ self.changed(\redraw);
+ },
+
+ set_bank: { arg self, idx;
+ self.model.bank = idx;
+ self.changed(\redraw);
+ },
+
+ get_sample_xy: { arg self, x, y;
+ self.model.samplelist[ (self.model.bank * 32) + (x * 4) + y ];
+ },
+
+ choose: { arg self, action;
+ ~kbpad8x4.do { arg line, iy;
+ line.do { arg key, ix;
+ self.kb_handler[[0, key]] = { action.(self.get_sample_xy(ix, iy) )};
+ }
+ };
+
+ ~kbnumpad.do { arg keycode, idx;
+ self.kb_handler[[0, keycode]] = { self.set_bank(idx) };
+ };
+ },
+
+ init: { arg self;
+ var parent;
+ parent = Window.new("Sample Lib",Rect(100,Window.screenBounds.height-400, 1220,300));
+ ~samplelib_view.(parent, self);
+
+ parent.view.keyDownAction = { arg view, char, modifiers, u, k;
+ u.debug("slooooooooooooo u");
+ modifiers.debug("slooooooooooooo modifiers");
+ self.kb_handler.debug("kb");
+ self.kb_handler[[modifiers,u]].value
+ };
+ parent.front;
+
+ }
+
+ );
+ obj.init;
+ obj;
+
+};
+
+~choose_sample = { arg main, action;
+ var sl;
+ sl = ~make_samplelib.(main);
+ sl.choose(action);
+};
+
+~choose_sample.(nil, { arg x; x.debug("yeak") });
+
+)
+
+(
+
+w = Window.new("Text View Example",Rect(100,Window.screenBounds.height-400, 520,300)).front;
+
+t = TextView(w.asView,Rect(10,10, 100,200))
+
+.focus(true).editable_(false).background_(w.view.background).string_("plsdkfsdfkljm\nsdlfkjsdflksdfjkmfsklfkmljsmkjfmjkskdjmsfdjkmsdjkm");
+
+)
+(
+
+w = Window.new("Text View Example",Rect(100,Window.screenBounds.height-400, 520,300)).front;
+
+t = StaticText(w.asView,Rect(10,10, 100,200));
+t.string = "plopopop";
+
+
+)
View
330 seqpanel.sc
@@ -0,0 +1,330 @@
+(
+
+~seq_view = { arg parent, seq, paramlist;
+ var midi;
+ var width = 1200;
+ var row_layout;
+ var sc_seq;
+ var seq_messages;
+
+ row_layout = GUI.vLayoutView.new(parent, Rect(0,0,(width+10),800));
+ row_layout.background = ~editplayer_color_scheme.background;
+
+ ~midi_interface.clear_assigned(\slider);
+ ~midi_interface.clear_assigned(\knob);
+
+ CCResponder.removeAll; // FIXME: must not remove other useful CCResponders
+
+ seq_messages = Dictionary.newFrom((
+ paramlist: { arg self;
+ var player;
+ var master;
+ var midi;
+
+ row_layout.removeAll;
+
+ "hah33333333ahahahjkkj".debug;
+ self.get_paramlist.do { arg paramasso, i;
+ var player_name = paramasso.key;
+ var param = paramasso.value;
+
+
+ player = seq.get_player_from_name(player_name);
+
+ if(param.name == \noteline, {
+ midi = ~piano_recorder.(player);
+ param.midi = midi;
+ ~make_noteline_view.(row_layout, seq.make_param_display(param, i), param);
+ },{
+ param.midi = nil;
+ "hahahahahjkkj".debug;
+ ~make_stepline_view.(row_layout, seq.make_param_display(param, i), param, midi);
+ });
+
+ };
+ }
+ ));
+
+ sc_seq = SimpleController(seq);
+ ~init_controller.(sc_seq, seq_messages);
+ seq.refresh.();
+
+ // remove func
+
+ row_layout.onClose = {
+ sc_seq.remove;
+ };
+
+};
+
+~make_seq = { arg main, parent, kb_handler;
+
+ var seq;
+
+ seq = (
+
+ model: (
+ param_offset: 0@0,
+ max_cells: 32,
+ selected_param: main.state.panel.seqpanel.selected_player_idx;
+ ),
+
+ make_param_display: { arg self, param, idx;
+ (
+ get_bank: { arg self;
+ main.state.panel.seqpanel.bank
+ },
+ selected: { arg self;
+ if(idx.debug("idx") == seq.model.selected_param.debug("sel"), {1}, {0});
+ },
+ max_cells: { arg self;
+ seq.model.max_cells;
+ },
+ get_selected_cell: {
+ param.get_selected_cell;
+ },
+ show_midibloc: false,
+ name: { arg self;
+ var pname;
+ pname.debug("pname");
+ param.dump.debug("param");
+ pname = seq.get_paramlist[idx].key;
+ pname.debug("pname");
+ },
+ noteline_numbeats: 32,
+ cell_width: 30,
+ width: 200,
+ height: 30,
+ name_width: { arg self;
+ 80;
+ }
+ );
+ },
+
+ get_param_at: { arg self, idx;
+ self.get_paramlist[idx].value;
+ },
+
+ get_selected_param: { arg self;
+ self.get_param_at( seq.model.selected_param )
+ },
+
+ get_selected_player: { arg self;
+ var pname;
+ pname = self.get_paramlist[seq.model.selected_param].key;
+ main.model.livenodepool[pname];
+ },
+
+ get_player_from_name: { arg self, name;
+ main.model.livenodepool[name];
+ },
+
+ // control API
+
+ select_param: { arg self, idx;
+ var param, oldparam;
+ if(idx < (self.get_paramlist.size), {
+ oldparam = self.get_param_at(seq.model.selected_param);
+ param = self.get_param_at(idx);
+ seq.model.selected_param = idx;
+ main.state.panel.seqpanel.selected_player = self.get_selected_player;
+ main.state.panel.seqpanel.selected_player_idx = idx;
+ oldparam.changed(\selected);
+ param.changed(\selected);
+ }, {
+ idx.debug("selected param out of range");
+ });
+ },
+
+ get_offset_amount: { arg self;
+ var dur;
+ dur = self.get_selected_player.get_arg(\dur).preset;
+ dur.val[dur.selected_cell];
+ },
+
+ select_cell: { arg self, idx;
+ var sel, dur, player;
+ sel = self.get_selected_param.();
+ player = self.get_selected_player;
+ switch( sel.classtype,
+ \stepline, {
+ sel.toggle_cell(idx);
+ },
+ \noteline, {
+ sel.set_start_offset(idx*self.get_offset_amount);
+ },
+ \control, {
+ sel.select_cell(idx);
+ }
+ );
+ },
+
+ set_value: { arg self, val;
+ self.get_selected_param.set_value(val);
+ },
+
+ add_cell_bar: { arg self;
+ var bar_length = 4;
+ var dur;
+ var par = self.get_selected_param;
+ var defval = self.get_selected_param.default_val;
+
+ self.get_selected_param.debug("editplayer.controller.add_cell_bar get sel param");
+
+ switch(par.classtype,
+ \stepline, {
+ self.get_selected_param.add_cells( self.get_selected_param.get_cells.deepCopy);
+ },
+ \noteline, {
+ par.set_end_offset(par.get_end_offset+self.get_offset_amount);
+ par.get_end_offset.debug("set end offset");
+ },
+ \control, {
+ self.get_selected_param.add_cells( par.default_val ! bar_length);
+ }
+ );
+ },
+
+ remove_cell_bar: { arg self;
+ var bar_length = 4, dur;
+ var par = self.get_selected_param;
+ switch(par.classtype,
+ \stepline, {
+ self.get_selected_param.remove_cells(bar_length);
+ },
+ \noteline, {
+ par.set_end_offset(par.get_end_offset-self.get_offset_amount);
+ },
+ \control, {
+ self.get_selected_param.remove_cells(bar_length);
+ }
+ );
+ },
+
+ change_kind: { arg self, kind;
+ var param = self.get_selected_param;
+ if(param.classtype == \control, {
+ self.get_selected_param.change_kind(kind);
+ });
+ },
+
+ get_paramlist: { arg self, offset=nil;
+ var list = List.new;
+ var player_instance;
+ offset = offset ?? self.model.param_offset;
+ main.model.parlive.sortedKeysValuesDo( { arg key, val;
+ if( ~compare_point.(key, offset).not, {
+ val.data.do { arg pname;
+ if(pname != 0, {
+ player_instance = main.model.livenodepool[pname];
+ if( player_instance.noteline, {
+ list.add(pname -> player_instance.get_arg(\noteline));
+ },{
+ list.add(pname -> player_instance.get_arg(\stepline));
+ });
+ });
+ };
+ })
+ }, ~compare_point);
+ list.do{ arg i; i.dump.debug("get_paramlist list") };
+ list;
+ },
+
+ get_bank: { arg self;
+ main.state.panel.seqpanel.bank
+ },
+
+ set_bank: { arg self, bank;
+ var player_instance;
+ main.state.panel.seqpanel.bank = bank;
+ self.get_paramlist.do { arg asso;
+ player_instance = main.model.livenodepool[asso.key];
+ player_instance.set_bank(bank);
+ };
+ main.state.panel.seqpanel.bank = bank;
+ },
+
+ refresh: { arg self;
+ self.changed(\paramlist);
+ },
+
+ init: { arg self;
+
+ main.state.panel.seqpanel.selected_player = self.get_selected_player;
+
+ ~kbnumpad.do { arg kc, i; kb_handler[[0, kc]] = {
+ self.model.param_offset = 0@i;
+ self.changed(\paramlist);
+ }};
+
+ ~kbpad8x4_flat.do { arg kc, i; kb_handler[[0, kc]] = {
+ seq.select_cell((self.get_bank*self.model.max_cells)+i)
+ } };
+
+ ~kbnumline.do { arg kc, i; kb_handler[[~modifiers.alt, kc]] = { self.select_param(i) } };
+
+
+ kb_handler[[~modifiers.alt, ~kbaalphanum["n"]]] = {
+ self.get_selected_player.set_noteline(true);
+ self.changed(\paramlist);
+ };
+ kb_handler[[~modifiers.alt, ~kbaalphanum["b"]]] = {
+ self.get_selected_player.set_noteline(false);
+ self.changed(\paramlist);
+ };
+
+
+ kb_handler[[~modifiers.alt, ~kbaalphanum["r"]]] = {
+ var midi;
+ "STARTRECORD!!".debug;
+ midi = self.get_selected_param.midi;
+ if(midi.notNil, {
+ midi.start_recording.();
+ midi.changed(\recording);
+ });
+ };
+ kb_handler[[~modifiers.alt, ~kbaalphanum["t"]]] = {
+ var sum = 0;
+ var sel = self.get_selected_param;
+ var midi = sel.midi;
+ if(midi.notNil, {
+ midi.stop_recording.();
+ midi.changed(\recording);
+ midi.track.debug("66666666666666666666666666666- this is record!!!!");
+
+ midi.track.do { arg no;
+ sum = sum + no.dur;
+ };
+ sum.debug("total sum");
+ sel.notes = midi.track;
+ sel.changed(\notes);
+ })
+ };
+ // playing
+
+ kb_handler[ [~modifiers.fx, ~kbfx[4]] ] = { self.get_selected_player.node.play };
+ kb_handler[ [~modifiers.fx, ~kbfx[5]] ] = { self.get_selected_player.node.stop };
+
+ // cells
+
+ kb_handler[[0, ~numpad.plus]] = { seq.add_cell_bar.() };
+ kb_handler[[~modifiers.ctrl, ~numpad.plus]] = { seq.remove_cell_bar.() };
+
+ ~kbnumpad.do { arg keycode, idx;
+ kb_handler[[0, keycode]] = { self.set_bank(idx) };
+ };
+
+ // make view
+
+ ~seq_view.(parent, seq);
+ }
+
+ );
+ seq.init;
+ seq;
+
+
+};
+
+
+)

0 comments on commit 89ccb7c

Please sign in to comment.