I see that SC comes with a lot of fancy GUI elements for a synth but a common one that I have not found is a piano keyboard preview where you press notes with mouse to preview sounds. Is there one ?
Welcome to the forum! The only one I know about and have used is KeyboardWindow
class from the “wslib” Quark. It’s old but may have the functionality you need…it does require a little programming to use. You need to assign functions to the downAction
and upAction
to do whatever you want (typically, play notes ). Here is a minimal example that plays an Event when a note is pressed:
Quarks.install("wslib")
thisProcess.recompile // only necessary if "wslib" was newly installed
s.boot
(
k = KeyboardWindow();
k.window.front;
k.downAction = { arg ch, note, vel;
[ch,note,vel].debug("down ch,note,vel");
(midinote: note, amp: vel/127, dur: 0.5).play
}
)
In general, you’ll likely want to (instead of playing an Event on note down, when you don’t know what duration to use) create a Synth on downAction
, store it in a Dictionary of notes that are down, then properly release the Synth on upAction
. Here is a minimal example of that:
(
var notes = ();
k = KeyboardWindow();
k.window.front;
k.downAction = { arg ch, note, vel;
[ch,note,vel].debug("down ch,note,vel");
if (notes[note].isNil) {
notes[note] = Synth(\default, [freq: note.midicps, amp: vel/127])
}
};
k.upAction = { arg ch, note, vel;
var synth = notes[note];
if (synth.notNil) {
synth.release(0.25);
notes[note] = nil;
}
};
)
Cheers,
Glen.
Thanks I also found that there is a GUI element it escaped my attention called Image. It has an openSVG method I could use to together with mouse events to do what I want.
https://doc.sccode.org/Classes/Image.html
But will also look at your Quark suggestion.