var <>scale;
*new {|midihandler, synthName=\default, bendRadius=1, panAcross=false, params=nil, amp=1.0, group=nil, onlyWhite=false, scale=nil|
- ^super.newCopyArgs(midihandler, synthName, bendRadius, panAcross, params, amp, group).midiInit.keyInit(onlyWhite, scale);
+ ^super.newCopyArgs(midihandler, synthName, bendRadius, panAcross, params, amp, group).midiInit.keyInit(onlyWhite, scale).polyKeyInit;
}
keyInit {|ow=false, sc=nil|
scale = sc ? Scale.chromatic();
notes = Array.newClear(128);
+ }
+ polyKeyInit {
midihandler.key_{|d, v, n|
if (this.isWhiteKey(n) || onlyWhite.not) {
if (onlyWhite) {
notes[n].set(\gate, 0);
notes[n] = nil;
};
+ } {
+ // black keys in onlyWhite mode
};
};
}
midiKeyToFreq {|n|
- "Playing %".format(scale.degreeToFreq(n-60, 60.midicps, 0).cpsmidi.round(0.001)).postln;
+ //"Playing %".format(scale.degreeToFreq(n-60, 60.midicps, 0).cpsmidi.round(0.001)).postln;
^scale.degreeToFreq(n-60, 60.midicps, 0) * bend.midiratio;
}
}
//=============================================================================
// connect synth to midi-keyboard, play only one note at a time
-KeySynthMono : MidiSynth {
+KeySynthMono : KeySynth {
var <note, <midinote;
+ var <>poly;
- *new {|midihandler, synthName=\default, bendRadius=1, panAcross=false, params=nil, amp=1.0, group=nil|
- ^super.newCopyArgs(midihandler, synthName, bendRadius, panAcross, params, amp, group).midiInit.keyInit;
+ *new {|midihandler, synthName=\default, bendRadius=1, panAcross=false, params=nil, amp=1.0, group=nil, onlyWhite=false, scale=nil, poly=false|
+ ^super.newCopyArgs(midihandler, synthName, bendRadius, panAcross, params, amp, group).midiInit.keyInit(onlyWhite, scale).monoKeyInit(poly);
}
- keyInit {
+ monoKeyInit {|aPoly=false|
+ poly = aPoly;
+
note = nil;
midinote = -1;
+ if (poly) {
+ this.params[\doneAction] = 0;
+ note = Synth(synthName, [\gate, 0], group);
+ };
midihandler.key_{|d, v, n|
+ if (onlyWhite) {
+ n = 60 + this.distanceWhite(60, n);
+ };
if (d) {
- if (note.notNil) {
- note.set(\gate, 0);
- };
- midinote = n;
- note = Synth(synthName, params.value.asPairs++[
+ var newFreq = this.midiKeyToFreq(n);
+ var newParams = params.value.asPairs++[
\gate, 1,
- \freq, (n+bend).midicps,
+ \freq, newFreq,
\amp, amp * v,
- ]++this.makePanParam(n), group);
+ ]++this.makePanParam(n);
+ midinote = n;
+ if (note.notNil) {
+ if (poly) {
+ note.set(*newParams);
+ } {
+ note.set(\gate, 0);
+ };
+ };
+ if (poly.not) {
+ note = Synth(synthName, newParams, group);
+ };
} {
if (n == midinote) {
note.set(\gate, 0);
- note = nil;
+ if (poly.not) {
+ note = nil;
+ };
};
};
};
free {
note.free;
- midihandler.key = nil;
- midihandler.bend = nil;
super.free;
}
}