2 summary:: Fast Responder for incoming MIDI Messages
3 categories:: External Control>MIDI
4 related:: Guides/MIDI, Classes/MIDIdef
7 MIDIFunc (and its subclass link::Classes/MIDIdef::) registers one or more functions to respond to an incoming MIDI message. Many of its methods are inherited from its superclass link::Classes/AbstractResponderFunc::.
9 note:: MIDIFunc and link::Classes/MIDIdef:: aim to improve upon the MIDIresponder classes by being faster and easier to use. They were made with the intention of creating a more convenient, logical and consistent interface, which shares a common design with link::Classes/OSCFunc:: and link::Classes/OSCdef::. As of this time, however, they still lack some features of the MIDIresponder classes, notably the learn method. Note that unlike those classes, MIDIFuncs are removed on Cmd-. by default. This can be overriden using either of the fix or permanent methods.::
13 private:: initClass, cmdPeriod
15 METHOD:: defaultDispatchers
16 Get or set an link::Classes/IdentityDictionary:: containing the default dispatcher objects for MIDIFuncs of different types (these are what you get if you pass nil as the dispatcher argument to link::#*new::). These objects will decide if any of their registered MIDIFuncs should respond to an incoming MIDI message. The dictionary should have the keys code::[\noteOn, \noteOff, \control, \polytouch, \touch, \program, \bend]:: and values of an appropriate subclass of link::Classes/AbstractDispatcher:: for each message type. By default these will be instances of link::Classes/MIDIMessageDispatcher:: for the the first four message types, and instances of link::Classes/MIDIMessageDispatcherNV:: for the last three.
18 returns:: The getter returns an link::Classes/IdentityDictionary::.
21 Create a new, enabled MIDIFunc. Normally one would use one of the message type specific convenience methods below, rather than use this method directly.
24 A link::Classes/Function:: or similar object which will respond to the incoming message. When evaluated for noteOn, noteOff, control, and polytouch messages it will be passed the arguments val, num, chan, and src, corresponding to the message value (e.g. velocity, control value, etc.), message number (e.g. note number), MIDI channel, and MIDI source uid. For touch, programme change and bend messages it will be passed only val, chan, and src.
27 An link::Classes/Integer:: indicating the MIDI message number (note number, control number, or programme number) for this MIDIFunc. This can be an array. If nil, the MIDIFunc will respond to messages of all possible message numbers.
30 An link::Classes/Integer:: indicating the MIDI channel number for this MIDIFunc. This can be an array. If nil, the MIDIFunc will respond to messages received on all channels.
33 A link::Classes/Symbol:: indicating which kind of MIDI message this MIDIFunc should respond to. One of code::\noteOn::, code::\noteOff::, code::\control::, code::\touch::, code::\polytouch::, code::\bend::, or code::program::.
36 An link::Classes/Integer:: corresponding to the uid of the MIDI input. (See link::Classes/MIDIClient::.) If nil, the MIDIFunc will respond to messages received from all sources.
38 argument:: argTemplate
39 An optional link::Classes/Integer:: or link::Classes/Function:: (or object which responds to the method link::Overviews/Methods#matchItem::) used to match the value of an incoming MIDI message. (e.g. velocity, control value, program number, etc.). If a Function, it will be evaluated with the message value as an argument, and should return a link::Classes/Boolean:: indicating whether the message matches and this MIDIFunc should respond.
42 An optional instance of an appropriate subclass of link::Classes/AbstractDispatcher::. This can be used to allow for customised dispatching. Normally this should not be needed.
44 returns:: A new instance of MIDIFunc.
47 A convenience method to create a new MIDIFunc which responds to MIDI control messages. See link::#*new:: for argument descriptions.
49 returns:: A new instance of MIDIFunc which responds to MIDI control messages.
52 A convenience method to create a new MIDIFunc which responds to MIDI note on messages. See link::#*new:: for argument descriptions.
54 returns:: A new instance of MIDIFunc which responds to MIDI note on messages.
57 A convenience method to create a new MIDIFunc which responds to MIDI note off messages. See link::#*new:: for argument descriptions.
59 returns:: A new instance of MIDIFunc which responds to MIDI note off messages.
62 A convenience method to create a new MIDIFunc which responds to MIDI polytouch messages. See link::#*new:: for argument descriptions.
64 returns:: A new instance of MIDIFunc which responds to MIDI polytouch messages.
67 A convenience method to create a new MIDIFunc which responds to MIDI touch messages. See link::#*new:: for argument descriptions.
69 returns:: A new instance of MIDIFunc which responds to MIDI touch messages.
72 A convenience method to create a new MIDIFunc which responds to MIDI bend messages. See link::#*new:: for argument descriptions.
74 returns:: A new instance of MIDIFunc which responds to MIDI bend messages.
77 A convenience method to create a new MIDIFunc which responds to MIDI program change messages. See link::#*new:: for argument descriptions.
79 returns:: A new instance of MIDIFunc which responds to MIDI program change messages.
83 private:: init, printOn
86 Get this MIDIFunc's MIDI channel number.
88 returns:: An link::Classes/Integer::.
91 Get this MIDIFunc's MIDI message number.
93 returns:: An link::Classes/Integer::.
96 Get this MIDIFunc's message type.
98 returns:: A link::Classes/Symbol::; one of code::\noteOn::, code::\noteOff::, code::\control::, code::\touch::, code::\polytouch::, code::\bend::, or code::program::.
105 MIDIFunc.cc({arg ...args; args.postln}, 1); // match cc 1
106 MIDIFunc.cc({arg ...args; args.postln}, 1, 1); // match cc1, chan 1
107 MIDIFunc.cc({arg ...args; args.postln}, (1..10)); // match cc 1-10
108 MIDIFunc.noteOn({arg ...args; args.postln}); // match any noteOn
110 MIDIIn.doNoteOnAction(1, 1, 64, 64); // spoof a note on
111 MIDIIn.doControlAction(1, 1, 1, 64); // spoof a cc
112 MIDIIn.doControlAction(1, 1, 9, 64);
113 MIDIIn.doControlAction(1, 10, 1, 64);