[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-users] Adding 2nd 'instrument' to Task (Josh, Slider Test)
I have hacked up Josh's slider test code to get one slider to control the mul of an instrument that continuously plays a 10 note equal tempered scale up and down controlled by a start/stop button.
I would like to add a second instrument that plays the same scale, inverted in relation to the first. The mul for the second instrument will be inverted also; mul2 = (1-mul1), and will take values from the same slider.
I suppose that means I need to send new synth messages to the same nodes as the first 'instrument'.
I do not want the sound to become stereophonic. Do I send pairs of new synth messages as an array and then mix them into a single channel? Do I need to assign nodes instead of using nextnode?
Also a glitch:
I need to click on the slider before the value of mul1 is sent to the server and I hear sound.
If I put mul = 0.5 in the SinOsc of the SynthDef, it stays at 0.5 and does not get the values from the slider. In short, I would like sound to start with the start/stop button.
My very hacked up version of Josh's code is copied below:
(
var w, sliders, numbers, initscale, action, taskfun, task, mul1, actionbutton;
SynthDef(\sin, {arg freq, mul;
Out.ar(0, SinOsc.ar(freq, 0, mul) * Line.kr(1, 0, 0.3, doneAction: 2))
}).load(s);
taskfun = {
task = Task({var scale, size;
scale = 1;
size = scale.size;
1000.do{arg i;
// score
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.0), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.1), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.2), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.3), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.4), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.5), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.6), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.7), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.8), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.9), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(5.0), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.9), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.8), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.7), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.6), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.5), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.4), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.3), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.2), \mul, mul1);0.2.wait;
s.sendMsg(\s_new, \sin, s.nextNodeID, 0, 1, \freq, octcps(4.1), \mul, mul1);0.2.wait;
(i == (size - 1)).if({actionbutton.valueAction_(0)})
}
}, AppClock).play;
};
//GUI
initscale = [1];
sliders = Array.newClear(1);
w = SCWindow("Loudeness Difference", Rect(100, 100, 500, 250)).front;
1.do{arg i;
sliders[i] = SCSlider.new(w, Rect(20, 30 + (i * 40), 400, 30))
.value_(initscale[i] / 2)
.action_({arg me;
w.view.children[w.view.children.indexOf(me) + 1].value = me.value.round(0.001);
mul1 = me.value.round(0.001);
});
SCNumberBox(w, Rect(430, 30 + (i * 40), 40, 30))
.value_(initscale[i] / 2)
.action_({arg me;
(me.value >= 0) && (me.value <= 1).if({
w.view.children[w.view.children.indexOf(me) - 1].value = (me.value / 2).round(0.001);
}, {
"Please enter a value between 0 and 1".postln;
})
})
};
SCStaticText(w, Rect(40, 30 + (1 * 40), 360, 30))
.string_("Instrument 1 <<<<<------------------------------------->>>>> Instrument 2");
action = "" {taskfun.value}];
actionbutton = SCButton(w, Rect(20, 30 + (3 * 40), 60, 30))
.states_([
["Start", Color.black, Color.white],
["Stop", Color.black, Color.grey]
])
.action_({arg me;
me.value.postln;
action[me.value].value;
});
SCButton(w, Rect(20, 30 + (4 * 40), 120, 30))
.states_([
["Save Slider Value", Color.black, Color.white]
])
.action_({
CocoaDialog.savePanel({arg path;
var file;
file = File.new(path, "w");
file.putString("[");
sliders.do{arg me, i; file.putString(me.value.round(0.001).asString ++
(i == (sliders.size-1)).if({""}, {", "}))};
file.putString("]");
file.close;
}, {"No File Selected- Nothing saved".postln;}
)
});
)