};
}
+ distanceWhite {|start, end|
+ var res = 0;
+ res = ((end-start) / 12).asInteger * 7;
+ if (end >= start) {
+ res = res + ((end-start) % 12).collect{|i| i}.count{|i| Scale.major.degrees.includesEqual((start+i+1) % 12)};
+ } {
+ res = res - ((start-end) % 12).collect{|i| i}.count{|i| Scale.major.degrees.includesEqual((start-i-1) % 12)};
+ };
+ ^res;
+ }
+
}
//=============================================================================
if (d) {
notes[n] = Synth(synthName, params.value.asPairs++[
\gate, 1,
- \freq, n.midicps,
+ \freq, (n+bend).midicps,
\amp, amp * v,
]++this.makePanParam(n), group);
} {
midihandler.ledPad(row, col, 2, 1, 1);
notes[midinote] = Synth(synthName, params.value.asPairs++[
\gate, 1,
- \freq, freq,
+ \freq, freq * bend.midiratio,
\amp, amp * v,
]++this.makePanParam(midinote), group);
amps[midinote] = amp * v;
midinote = n;
note = Synth(synthName, params.value.asPairs++[
\gate, 1,
- \freq, n.midicps,
+ \freq, (n+bend).midicps,
\amp, amp * v,
]++this.makePanParam(n), group);
} {
// connect synth to midi-keyboard, play only one note at a time, relative keys
KeySynthRelative : KeySynthMono {
- var <>centerKey, <>intervals, keyNote;
+ var <>centerKey, <>intervals, <>onlyWhite, keyNote;
- *new {|midihandler, synthName=\default, bendRadius=1, panAcross=false, params=nil, amp=1.0, group=nil, centerKey=60, intervals=#[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]|
+ *new {|midihandler, synthName=\default, bendRadius=1, panAcross=false, params=nil, amp=1.0, group=nil, centerKey=60, intervals=#[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], onlyWhite=true|
^super.newCopyArgs(
midihandler, synthName, bendRadius, panAcross, params, amp, group
- ).midiInit.keyInit.relInit(centerKey, intervals);
+ ).midiInit.keyInit.relInit(centerKey, intervals, onlyWhite);
}
- relInit {|c, i|
+ relInit {|c, i, ow|
centerKey = c;
intervals = i;
+ onlyWhite = ow;
keyNote = -1;
midinote = 60;
midihandler.key_{|d, v, n|
if (d) {
- if (note.notNil) {
- note.set(\gate, 0);
- };
+ var distance;
keyNote = n;
- midinote = case
- { (n-centerKey) == 0 } {
- midinote;
- }
- { (n-centerKey) > 0 } {
- midinote + intervals[n-centerKey-1];
- }
- { (n-centerKey) < 0 } {
- midinote - intervals[centerKey-n-1];
+ if (onlyWhite) {
+ distance = this.distanceWhite(centerKey, n);
+ } {
+ distance = n - centerKey;
+ };
+ [distance, intervals.size].postln;
+ if (distance.abs <= intervals.size) {
+ midinote = case
+ { distance == 0 } {
+ midinote;
+ }
+ { distance > 0 } {
+ midinote + intervals[distance-1];
+ }
+ { distance < 0 } {
+ midinote - intervals[-1-distance];
+ };
+ if (note.notNil) {
+ note.set(\gate, 0);
+ };
+ midinote.postln;
+ note = Synth(synthName, params.value.asPairs++[
+ \gate, 1,
+ \freq, (midinote+bend).midicps,
+ \amp, amp * v,
+ ]++this.makePanParam(midinote), group);
};
- midinote.postln;
- note = Synth(synthName, params.value.asPairs++[
- \gate, 1,
- \freq, midinote.midicps,
- \amp, amp * v,
- ]++this.makePanParam(midinote), group);
} {
if (n == keyNote) {
note.set(\gate, 0);