Skip to content

Instantly share code, notes, and snippets.

@tttapa
Created August 7, 2019 00:45
Show Gist options
  • Save tttapa/16046ad186b9abdc41974ba2d2036f6e to your computer and use it in GitHub Desktop.
Save tttapa/16046ad186b9abdc41974ba2d2036f6e to your computer and use it in GitHub Desktop.
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="1.8.16">
<compounddef id="d7/d4f/MIDIOutput_2Control-Change_2CCIncrementDecrementButtons_2CCIncrementDecrementButtons_8ino-example" kind="example">
<compoundname>MIDIOutput/Control-Change/CCIncrementDecrementButtons/CCIncrementDecrementButtons.ino</compoundname>
<briefdescription>
</briefdescription>
<detaileddescription>
<para><heading level="1"><ref refid="d3/d60/classCCIncrementDecrementButtons" kindref="compound">CCIncrementDecrementButtons</ref> </heading>
</para>
<para>This is an example that demonstrates the use of Increment and Decrement buttons that can be used for scrolling through a song list, tuning effects, etc. <linebreak/>
You can compare it to a rotary encoder, but with two buttons instead of an encoder. <linebreak/>
<linebreak/>
<heading level="2">Connections </heading>
</para>
<para><itemizedlist>
<listitem><para>5: momentary push button (to ground)</para>
</listitem><listitem><para>6: momentary push button (to ground)</para>
</listitem></itemizedlist>
</para>
<para>The internal pull-up resistors for the buttons will be enabled automatically.</para>
<para><heading level="2">Behavior </heading>
</para>
<para><itemizedlist>
<listitem><para>If the button on pin 5 is pressed, a MIDI CC increment message is sent.</para>
</listitem><listitem><para>If the button on pin 6 is pressed, a MIDI CC decrement message is sent.</para>
</listitem><listitem><para>The controller number <computeroutput><ref refid="d7/dc7/namespaceMCU_1a98e24a5d425041ee7eacd20ee96e653b" kindref="member">MCU::V_POT_1</ref></computeroutput> will be used.</para>
</listitem><listitem><para>If either of the buttons is pressed down for a longer time, it will keep on sending increment/decrement messages quickly until you release it (like a key on a computer keyboard). This is to make it easier to scroll a large amount, for example. The timing can be changed by tweaking <ref refid="db/d02/Settings_8hpp_1ae45a88a68c9a82d85febda88f7ecf96d" kindref="member">LONG_PRESS_DELAY</ref> and <ref refid="db/d02/Settings_8hpp_1a4c6482347c7ca829da34491dfb905773" kindref="member">LONG_PRESS_REPEAT_DELAY</ref> in <ref refid="db/d02/Settings_8hpp" kindref="compound">Settings/Settings.hpp</ref>.</para>
</listitem><listitem><para>If both buttons are pressed simultaneously, a MIDI Note On event is sent on note <computeroutput><ref refid="d7/dc7/namespaceMCU_1a2c878b62c3100688f78dd53814f450c6" kindref="member">MCU::V_POT_SELECT_1</ref></computeroutput>. <linebreak/>
(This is optional, you can just leave out the final argument to the constructor, and it won&apos;t send anything when you press both buttons at once).</para>
</listitem><listitem><para>The multiplier can be used to increment multiple ticks per each time you press a button. This is useful if you have to press the button for a very long time to get a substantial change.</para>
</listitem></itemizedlist>
</para>
<para>Map the Arduino as a Mackie Control Universal (<ref refid="d7/dc7/namespaceMCU" kindref="compound">MCU</ref>) or equivalent in your audio software.</para>
<ulink url="https://github.com/tttapa/Control-Surface">https://github.com/tttapa/Control-Surface</ulink> <programlisting filename="MIDIOutput/Control-Change/CCIncrementDecrementButtons/CCIncrementDecrementButtons.ino"><codeline></codeline>
<codeline><highlight class="preprocessor">#include<sp/>&lt;<ref refid="db/dbf/Control__Surface_8h" kindref="compound">Control_Surface.h</ref>&gt;</highlight><highlight class="normal"><sp/></highlight><highlight class="comment">//<sp/>Include<sp/>the<sp/>Control<sp/>Surface<sp/>library</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"></highlight><highlight class="comment">//<sp/>Instantiate<sp/>a<sp/>MIDI<sp/>over<sp/>USB<sp/>interface.</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><ref refid="de/d05/classUSBMIDI__Interface" kindref="compound">USBMIDI_Interface</ref><sp/>midi;</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"></highlight><highlight class="comment">//<sp/>Instantiate<sp/>a<sp/>CCIncrementDecrementButtons<sp/>object</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><ref refid="d3/d60/classCCIncrementDecrementButtons" kindref="compound">CCIncrementDecrementButtons</ref><sp/>buttons<sp/>=<sp/>{</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/>{5,<sp/>6},<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Button<sp/>pins:<sp/>5<sp/>increments,<sp/>6<sp/>decrements</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="d7/dc7/namespaceMCU_1a98e24a5d425041ee7eacd20ee96e653b" kindref="member">MCU::V_POT_1</ref>,<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Increment/Decrement<sp/>CC<sp/>address</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/>1,<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Multiplier</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="d7/dc7/namespaceMCU_1a2c878b62c3100688f78dd53814f450c6" kindref="member">MCU::V_POT_SELECT_1</ref>,<sp/></highlight><highlight class="comment">//<sp/>Reset<sp/>note<sp/>address</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal">};</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>setup()<sp/>{</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Use<sp/>the<sp/>Mackie<sp/>Control<sp/>protocol<sp/>for<sp/>sending<sp/>relative<sp/>MIDI<sp/>CC<sp/>messages.</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="d3/dd0/classRelativeCCSender_1a410968eabefd14077e163792aa679c0c" kindref="member">RelativeCCSender::setMode</ref>(<ref refid="d9/d24/RelativeCCSender_8hpp_1af7774143941c236448d7c53f4347276b" kindref="member">MACKIE_CONTROL_RELATIVE</ref>);</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="d9/d38/Control__Surface__Class_8cpp_1af7a5d250297d82b2b29605dd7ac250df" kindref="member">Control_Surface</ref>.<ref refid="dc/d45/classControl__Surface___1a1fda63983d83a8be20302e9fef48f63e" kindref="member">begin</ref>();<sp/></highlight><highlight class="comment">//<sp/>Initialize<sp/>Control<sp/>Surface</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal">}</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>loop()<sp/>{</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="d9/d38/Control__Surface__Class_8cpp_1af7a5d250297d82b2b29605dd7ac250df" kindref="member">Control_Surface</ref>.<ref refid="dc/d45/classControl__Surface___1a69fd0ae13604c39d6dc0da12fc94a18f" kindref="member">loop</ref>();<sp/></highlight><highlight class="comment">//<sp/>Update<sp/>the<sp/>control<sp/>surface</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal">}</highlight></codeline>
</programlisting> </para>
</detaileddescription>
</compounddef>
</doxygen>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment