KeyboardWindow
part of wslib
a keyboard window.
KeyboardWindow ( nKeys, startOctave, channel, bounds )
creates a new instance.
k = KeyboardWindow();
The vertical clicking position equals velocity, which is visualized by the color of the key (amount of red).
If the mouse is moved out of the key's area while pressed, the note will hold until clicked again.
downAction, upAction
these variables contain Functions to be executed when a key is pressed or released.
The default downAction posts an array containing the received arguments:
channel ( as defined during creation), midi note number, midi velocity (0-127)
(
// a simple keyboard implementation using Groups for every possible note
s = Server.default;
36.do({ |i| s.sendMsg( \g_new, 500 + 36 + i ); }); // run this line again after cmd-.
k.downAction = { |chan, note, velo| s.sendMsg( \s_new, "default", s.nextNodeID, 1, 500 + note,
\freq, note.midicps, \amp, (velo/127) * 0.25 );
};
k.upAction = { |chan, note, velo|
// release velo changes release time (0-1s)
s.sendMsg( \n_set, 500 + note, "gate", -1 - (velo / 127.0) )
};
)
pressNote ( noteNumber, velo ), unPressNote ( noteNumber, velo )
press and unpress notes from the lang
k.pressNote( 60, 40 );
k.unPressNote( 60 );
These can also be called driectly on the Class. Then an extra argument is added: channel
This will press or unpress notes in all open windows with the specified channel
KeyboardWindow.pressNote( 59, 60, 0 );
KeyboardWindow.unPressNote( 59, 60, 0 );
unPressAll ( velo ), *unPressAll ( velo, channel )
press and unpress all notes from the lang
10.do({ k.pressNote( 36 + 36.rand, 64.rand + 1 ) }); // 10 random notes
k.unPressAll;
activeNotes
array with currently active notes. Last item is always the last note press
10.do({ k.pressNote( 36 + 36.rand, 64.rand + 1 ) }); // 10 random notes
k.activeNotes;
k.unPressAll;