{"id":854,"date":"2013-03-08T12:51:49","date_gmt":"2013-03-08T10:51:49","guid":{"rendered":"http:\/\/tomashg.com\/?p=854"},"modified":"2013-05-15T17:07:49","modified_gmt":"2013-05-15T15:07:49","slug":"midi-elements-teensy-library","status":"publish","type":"post","link":"https:\/\/tomashg.com\/?p=854","title":{"rendered":"MIDI Elements Teensy Library"},"content":{"rendered":"<p><a href=\"https:\/\/tomashg.com\/wp-content\/uploads\/2013\/03\/midiElements.jpg\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-894\" title=\"midiElements\" src=\"https:\/\/tomashg.com\/wp-content\/uploads\/2013\/03\/midiElements.jpg\" alt=\"\" width=\"680\" height=\"114\" srcset=\"https:\/\/tomashg.com\/wp-content\/uploads\/2013\/03\/midiElements.jpg 680w, https:\/\/tomashg.com\/wp-content\/uploads\/2013\/03\/midiElements-300x50.jpg 300w\" sizes=\"(max-width: 680px) 100vw, 680px\" \/><\/a><\/p>\n<p>I have created a wrapper library to make programming MIDI controllers on the Teensy board dead easy and super fast. Simply instantiate object for each component like Buttons, Potentiometer, LED, rotary encoders, etc. and let the library handle all the dirty work of reading the raw values and deciding when to send MIDI signals. Enabling you to experiment and concentrate on your creative ideas and not waste too much time with the repetitive technical details and debugging code.<\/p>\n<p>Just in a couple lines of code you can program a fully functioning MIDI controller.<br \/>\nHere&#8217;s an example of how simple things are:<\/p>\n<pre class=\"brush:cpp\">boolean debug=false; \/\/ print to serial instead of midi\r\nboolean secondary=true; \/\/ enable secondary midi messages\r\nint midiChannel=1; \/\/ midi channel number\r\n\r\n\/\/ declare all your components here\r\nButton but(17,midiChannel,1,secondary,debug); \/\/ button 1 on pin 17\r\nButton but2(16,midiChannel,2,secondary,debug); \/\/ button 2 on pin 16\r\nPotentiometer pot(45,midiChannel,3,secondary,debug); \/\/ knob on pin 45 (A7)\r\nLed led(15,midiChannel,3,true); \/\/ led on pin 15 with PWM enabled, triggered on the same number as pot\r\n\r\nvoid setup(){\r\n  usbMIDI.setHandleControlChange(OnControlChange); \/\/ set event handler for CC\r\n}\r\n\r\nvoid loop(){\r\n  \/\/ add here all the input component reads\r\n  pot.read(); \/\/ read knob and send midi messages\r\n  but.read(); \/\/ read buttons and send midi messages\r\n  but2.read();\r\n  usbMIDI.read(); \/\/ read all the incoming midi messages\r\n}\r\n\/\/====================================================================\r\n\/\/ event handlers\r\nvoid OnControlChange(byte channel, byte control, byte value){\r\n  \/\/ add all your output component sets that will trigger with cc\r\n  led.setOn(channel,control,value);\r\n}<\/pre>\n<p>Currently only Buttons, Potentiometers and LEDs are supported. But I&#8217;m planning on adding RGB LED, rotary encoder, LED bars and ring and button pad classes.<br \/>\nEach component sends two sets of MIDI signals if enabled. For example Buttons send NoteOn, NoteOff, as well as ControlChange values so that they could be easily mapped in Toggle or Instant mode in software like Ableton Live. Also the Potentiometers send secondary NoteOns when values reach 0 or 127, \u00e0 la MIDI Fighter Pro.<\/p>\n<p><strong>Download:<\/strong> <a href=\"https:\/\/github.com\/ghztomash\/MIDIElements\">github<\/a><br \/>\nTo install extract the MIDIElements folder in your arduino\/libraries directory<\/p>\n<p><!--more--><\/p>\n<p>Here are the methods for each class:<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Button:<\/strong><\/span><br \/>\n<em>Constructors<\/em><\/p>\n<p><strong>Button(byte pin);<\/strong><br \/>\nCreates a button object with default channel 0, MIDI number 0 and debugging enabled<br \/>\npin &#8211; pin number on Teensy<\/p>\n<p><strong>Button(byte pin, byte channel, byte number);<\/strong><br \/>\nCreates a button object on specified channel and MIDI number<br \/>\npin &#8211; pin number on Teensy<br \/>\nchannel &#8211; midi channel on which messages will be sent<br \/>\nnumber &#8211; midi value on which messages will be sent<\/p>\n<p><strong>Button(byte pin, byte channel, byte number, bool secondary);<\/strong><br \/>\nCreates a button object on specified channel and MIDI number<br \/>\npin &#8211; pin number on Teensy<br \/>\nchannel &#8211; midi channel on which messages will be sent<br \/>\nnumber &#8211; midi value on which messages will be sent<br \/>\nsecondary &#8211; send secondary midi signals<\/p>\n<p><strong>Button(byte pin, byte channel, byte number, bool secondary, bool debugging);<\/strong><br \/>\nCreates a button object on specified channel and MIDI number<br \/>\npin &#8211; pin number on Teensy<br \/>\nchannel &#8211; midi channel on which messages will be sent<br \/>\nnumber &#8211; midi value on which messages will be sent<br \/>\nsecondary &#8211; send secondary midi signals<br \/>\ndebugging &#8211; print messages to serial port instead of midi<\/p>\n<p><em>Functions<\/em><br \/>\n<strong>read();<\/strong><br \/>\nReads the button state and sends a midi note on if the button was pressed and note off if the button was unpressed on the channel and midi number specified in the constructor<\/p>\n<p><strong>readValue(bool &amp;stateChanged);<\/strong><br \/>\nReads the button state, and sets the stateChanged if the state changed from the last time checked, also returns true if the button is pressed and false if not pressed. No MIDI signals are sent.<br \/>\nstateChanged &#8211; is set to true after the function exits if the button state changed state<\/p>\n<p><strong>setVelocity(byte velocity);<\/strong><br \/>\nChanges the velocity value for note on messages, default velocity is 127.<br \/>\nvelocity &#8211; note on velocity<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Potentiometer:<\/strong><\/span><br \/>\n<em>Constructors<\/em><\/p>\n<p><strong>Potentiometer(byte pin);<\/strong><br \/>\nCreates a potentiometer object with default channel 0, MIDI number 0 and debugging enabled<br \/>\npin &#8211; pin number on Teensy<\/p>\n<p><strong>Potentiometer(byte pin, byte channel, byte number);<\/strong><br \/>\nCreates a potentiometer object on specified channel and MIDI CC number<br \/>\npin &#8211; pin number on Teensy<br \/>\nchannel &#8211; midi channel on which messages will be sent<br \/>\nnumber &#8211; midi value on which messages will be sent<\/p>\n<p><strong>Potentiometer(byte pin, byte channel, byte number, bool secondary);<\/strong><br \/>\nCreates a potentiometer object on specified channel and MIDI number<br \/>\npin &#8211; pin number on Teensy<br \/>\nchannel &#8211; midi channel on which messages will be sent<br \/>\nnumber &#8211; midi value on which messages will be sent<br \/>\nsecondary &#8211; send secondary midi signals<\/p>\n<p><strong>Potentiometer(byte pin, byte channel, byte number, bool secondary, bool debugging);<\/strong><br \/>\nCreates a potentiometer object on specified channel and MIDI number<br \/>\npin &#8211; pin number on Teensy<br \/>\nchannel &#8211; midi channel on which messages will be sent<br \/>\nnumber &#8211; midi value on which messages will be sent<br \/>\nsecondary &#8211; send secondary midi signals<br \/>\ndebugging &#8211; print messages to serial port instead of midi<\/p>\n<p><em>Functions<\/em><br \/>\n<strong>read();<\/strong><br \/>\nReads the potentiometer value and sends a control changed if the value changed on the channel and midi number specified in the constructor<\/p>\n<p><strong>readValue(bool &amp;stateChanged);<\/strong><br \/>\nReads the potentiometer value, and sets the stateChanged if the state changed from the last time checked, also returns the value of the potentiometer. No MIDI signals are sent.<br \/>\nstateChanged &#8211; is set to true after the function exits if the button state changed state<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Led:<\/strong><\/span><br \/>\n<em>Constructors<\/em><\/p>\n<p><strong>Led(byte pin);<\/strong><br \/>\nCreates a Led object with default channel 0, MIDI number 0 and debugging enabled<br \/>\npin &#8211; pin number on Teensy<\/p>\n<p><strong>Led(byte pin, byte channel, byte number);<\/strong><br \/>\nCreates a Led object on specified channel and MIDI CC number<br \/>\npin &#8211; pin number on Teensy<br \/>\nchannel &#8211; midi channel on which led will be triggered<br \/>\nnumber &#8211; midi value on which led will be triggered<\/p>\n<p><strong>Ledr(byte pin, byte channel, byte number, bool pwm);<\/strong><br \/>\nCreates a Led object on specified channel and MIDI number<br \/>\npin &#8211; pin number on Teensy<br \/>\nchannel &#8211; midi channel on which led will be triggered<br \/>\nnumber &#8211; midi value on which led will be triggered<br \/>\npwm &#8211; enable pulse width modulation<\/p>\n<p><em>Functions<\/em><br \/>\n<strong>setOn(byte channel, byte number, byte velocity);<\/strong><br \/>\nCall from within Note On or Control Change event handler and pass on the parameters. And the LED will turn on if the messages received correspond to those specified in the constructor.<br \/>\nchannel &#8211; midi channel of the received message<br \/>\nnumber &#8211; midi number or control change of the received message<br \/>\nvelocity &#8211; midi velocity or control change value of the received message<\/p>\n<p><strong>setOff(byte channel, byte number, byte velocity);<\/strong><br \/>\nCall from within Note Off event handler and pass on the parameters. And the LED will turn off if the messages received correspond to those specified in the constructor.<br \/>\nchannel &#8211; midi channel of the received message<br \/>\nnumber &#8211; midi number or control change of the received message<br \/>\nvelocity &#8211; midi velocity or control change value of the received message<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have created a wrapper library to make programming MIDI controllers on the Teensy board dead easy and super fast. Simply instantiate object for each component like Buttons, Potentiometer, LED, rotary encoders, etc. and let the library handle all the dirty work of reading the raw values and deciding when to send MIDI signals. Enabling [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112,32],"tags":[40,15,148,94,233,149],"class_list":["post-854","post","type-post","status-publish","format-standard","hentry","category-controllers","category-technology","tag-c","tag-framework","tag-library","tag-midi","tag-teensy","tag-wrapper"],"_links":{"self":[{"href":"https:\/\/tomashg.com\/index.php?rest_route=\/wp\/v2\/posts\/854","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tomashg.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tomashg.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tomashg.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tomashg.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=854"}],"version-history":[{"count":43,"href":"https:\/\/tomashg.com\/index.php?rest_route=\/wp\/v2\/posts\/854\/revisions"}],"predecessor-version":[{"id":926,"href":"https:\/\/tomashg.com\/index.php?rest_route=\/wp\/v2\/posts\/854\/revisions\/926"}],"wp:attachment":[{"href":"https:\/\/tomashg.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tomashg.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tomashg.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}