From bb3048d92ec1298c5ad1443f67a6122204a4deb7 Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Fri, 14 Aug 2015 14:56:31 -0400
Subject: [PATCH] ported: "*added MIDI support to K12 module, updated pd.tk and
 build process" from pd-l2ork: 7c485f595a430ac4539d67d091390f08c69f08c8

---
 l2ork_addons/K12/doc/GM_instrument_list.html  | 225 ++++++++++++++++++
 .../doc/MIDI_Standard_Controller_Numbers.html | 196 +++++++++++++++
 l2ork_addons/K12/midi_control-help.pd         |  62 +++++
 l2ork_addons/K12/midi_control.pd              |  27 +++
 l2ork_addons/K12/midi_instrument-help.pd      |  51 ++++
 l2ork_addons/K12/midi_instrument.pd           |  23 ++
 l2ork_addons/K12/midi_note-help.pd            |  51 ++++
 l2ork_addons/K12/midi_note.pd                 |  40 ++++
 l2ork_addons/K12/midi_synth-help.pd           |  66 +++++
 l2ork_addons/K12/midi_synth.pd                |  32 +++
 l2ork_addons/K12/preset-help.pd               |  28 ++-
 pd/src/pd.tk                                  |  27 ++-
 12 files changed, 816 insertions(+), 12 deletions(-)
 create mode 100644 l2ork_addons/K12/doc/GM_instrument_list.html
 create mode 100644 l2ork_addons/K12/doc/MIDI_Standard_Controller_Numbers.html
 create mode 100644 l2ork_addons/K12/midi_control-help.pd
 create mode 100644 l2ork_addons/K12/midi_control.pd
 create mode 100644 l2ork_addons/K12/midi_instrument-help.pd
 create mode 100644 l2ork_addons/K12/midi_instrument.pd
 create mode 100644 l2ork_addons/K12/midi_note-help.pd
 create mode 100644 l2ork_addons/K12/midi_note.pd
 create mode 100644 l2ork_addons/K12/midi_synth-help.pd
 create mode 100644 l2ork_addons/K12/midi_synth.pd

diff --git a/l2ork_addons/K12/doc/GM_instrument_list.html b/l2ork_addons/K12/doc/GM_instrument_list.html
new file mode 100644
index 000000000..bd44f04c7
--- /dev/null
+++ b/l2ork_addons/K12/doc/GM_instrument_list.html
@@ -0,0 +1,225 @@
+<html>
+<head>
+<title>MIDI GM Preset Chart</title>
+<div itemprop="articleBody">
+<h1>General MIDI preset chart</h1>
+<p>Here is a complete list of the 128 instruments and sounds defined by the General MIDI standard.</p>
+<table class="table table-striped" width="100%">
+<tbody>
+<tr>
+<td>
+<table border="0">
+<tbody>
+<tr>
+<td>PIANO</td>
+</tr>
+<tr>
+<td>01 - Acoustic Grand<br />02 - Bright Acoustic<br />03 - Electric Grand<br />04 - Honky-Tonk<br />05 - Electric Piano 1<br />06 - Electric Piano 2<br />07 - Harpsichord<br />08 - Clavinet</td>
+</tr>
+</tbody>
+</table>
+</td>
+<td>
+<table border="0">
+<tbody>
+<tr>
+<td>CHROM. PERCUS.</td>
+</tr>
+<tr>
+<td>09 - Celesta<br />10 - Glockenspiel<br />11 - Music Box<br />12 - Vibraphone<br />13 - Marimba<br />14 - Xylophone<br />15 - Tubular Bells<br />16 - Dulcimer</td>
+</tr>
+</tbody>
+</table>
+</td>
+<td>
+<table border="0">
+<tbody>
+<tr>
+<td>ORGAN</td>
+</tr>
+<tr>
+<td>17 - Drawbar Organ<br />18 - Percussive Organ<br />19 - Rock Organ<br />20 - Church Organ<br />21 - Reed Organ<br />22 - Accoridan<br />23 - Harmonica<br />24 - Tango Accordian</td>
+</tr>
+</tbody>
+</table>
+</td>
+<td>
+<table border="0">
+<tbody>
+<tr>
+<td>GUITAR</td>
+</tr>
+<tr>
+<td>25 - Nylon String Guitar<br />26 - Steel String Guitar<br />27 - Electric Jazz Guitar<br />28 - Electric Clean Guitar<br />29 - Electric Muted Guitar<br />30 - Overdriven Guitar<br />31 - Distortion Guitar<br />32 - Guitar Harmonics</td>
+</tr>
+</tbody>
+</table>
+</td>
+</tr>
+<tr>
+<td colspan="4">&nbsp;</td>
+</tr>
+<tr>
+<td>
+<table border="0">
+<tbody>
+<tr>
+<td>BASS</td>
+</tr>
+<tr>
+<td>33 - Acoustic Bass<br />34 - Electric Bass(finger)<br />35 - Electric Bass(pick)<br />36 - Fretless Bass<br />37 - Slap Bass 1<br />38 - Slap Bass 2<br />39 - Synth Bass 1<br />40 - Synth Bass 2</td>
+</tr>
+</tbody>
+</table>
+</td>
+<td>
+<table border="0">
+<tbody>
+<tr>
+<td>SOLO STRINGS</td>
+</tr>
+<tr>
+<td>41 - Violin<br />42 - Viola<br />43 - Cello<br />44 - Contrabass<br />45 - Tremolo Strings<br />46 - Pizzicato Strings<br />47 - Orchestral Strings<br />48 - Timpani</td>
+</tr>
+</tbody>
+</table>
+</td>
+<td>
+<table border="0">
+<tbody>
+<tr>
+<td>ENSEMBLE</td>
+</tr>
+<tr>
+<td>49 - String Ensemble 1<br />50 - String Ensemble 2<br />51 - SynthStrings 1<br />52 - SynthStrings 2<br />53 - Choir Aahs<br />54 - Voice Oohs<br />55 - Synth Voice<br />56 - Orchestra Hit</td>
+</tr>
+</tbody>
+</table>
+</td>
+<td>
+<table border="0">
+<tbody>
+<tr>
+<td>BRASS</td>
+</tr>
+<tr>
+<td>57 - Trumpet<br />58 - Trombone<br />59 - Tuba<br />60 - Muted Trumpet<br />61 - French Horn<br />62 - Brass Section<br />63 - SynthBrass 1<br />64 - SynthBrass 2</td>
+</tr>
+</tbody>
+</table>
+</td>
+</tr>
+<tr>
+<td colspan="4">&nbsp;</td>
+</tr>
+<tr>
+<td>
+<table border="0">
+<tbody>
+<tr>
+<td>REED</td>
+</tr>
+<tr>
+<td>65 - Soprano Sax<br />66 - Alto Sax<br />67 - Tenor Sax<br />68 - Baritone Sax<br />69 - Oboe<br />70 - English Horn<br />71 - Bassoon<br />72 - Clarinet</td>
+</tr>
+</tbody>
+</table>
+</td>
+<td>
+<table border="0">
+<tbody>
+<tr>
+<td>PIPE</td>
+</tr>
+<tr>
+<td>73 - Piccolo<br />74 - Flute<br />75 - Recorder<br />76 - Pan Flute<br />77 - Blown Bottle<br />78 - Skakuhachi<br />79 - Whistle<br />80 - Ocarina</td>
+</tr>
+</tbody>
+</table>
+</td>
+<td>
+<table border="0">
+<tbody>
+<tr>
+<td>SYNTH LEAD</td>
+</tr>
+<tr>
+<td>81 - Square Wave<br />82 - Saw Wave<br />83 - Syn. Calliope<br />84 - Chiffer Lead<br />85 - Charang<br />86 - Solo Vox<br />87 - 5th Saw Wave<br />88 - Bass& Lead</td>
+</tr>
+</tbody>
+</table>
+</td>
+<td>
+<table border="0">
+<tbody>
+<tr>
+<td>SYNTH PAD</td>
+</tr>
+<tr>
+<td>89 - Fantasia<br />90 - Warm Pad<br />91 - Polysynth<br />92 - Space Voice<br />93 - Bowed Glass<br />94 - Metal Pad<br />95 - Halo Pad<br />96 - Sweep Pad</td>
+</tr>
+</tbody>
+</table>
+</td>
+</tr>
+<tr>
+<td colspan="4">&nbsp;</td>
+</tr>
+<tr>
+<td>
+<table border="0">
+<tbody>
+<tr>
+<td>SYNTH EFFECTS</td>
+</tr>
+<tr>
+<td>97 - Ice Rain<br />98 - Soundtrack<br />99 - Crystal<br />100 - Atmosphere<br />101 - Brightness<br />102 - Goblin<br />103 - Echo Drops<br />104 - Star Theme</td>
+</tr>
+</tbody>
+</table>
+</td>
+<td>
+<table border="0">
+<tbody>
+<tr>
+<td>ETHNIC</td>
+</tr>
+<tr>
+<td>105 - Sitar<br />106 - Banjo<br />107 - Shamisen<br />108 - Koto<br />109 - Kalimba<br />110 - Bagpipe<br />111 - Fiddle<br />112 - Shanai</td>
+</tr>
+</tbody>
+</table>
+</td>
+<td>
+<table border="0">
+<tbody>
+<tr>
+<td>PERCUSSIVE</td>
+</tr>
+<tr>
+<td>113 - Tinkle Bell<br />114 - Agogo<br />115 - Steel Drums<br />116 - Woodblock<br />117 - Taiko Drum<br />118 - Melodic Tom<br />119 - Synth Drum<br />120 - Reverse Cymbal</td>
+</tr>
+</tbody>
+</table>
+</td>
+<td>
+<table border="0">
+<tbody>
+<tr>
+<td>SOUND EFFECTS</td>
+</tr>
+<tr>
+<td>121 - Guitar Fret Noise<br />122 - Breath Noise<br />123 - Seashore<br />124 - Bird Tweet<br />125 - Telephone Ring<br />126 - Helicopter<br />127 - Applause<br />128 - Gunshot</td>
+</tr>
+</tbody>
+</table>
+</td>
+</tr>
+</tbody>
+</table>	</div>
+</div>
+</div>
+</div>
+</div>
+</body>
+</html>
\ No newline at end of file
diff --git a/l2ork_addons/K12/doc/MIDI_Standard_Controller_Numbers.html b/l2ork_addons/K12/doc/MIDI_Standard_Controller_Numbers.html
new file mode 100644
index 000000000..ef63849d7
--- /dev/null
+++ b/l2ork_addons/K12/doc/MIDI_Standard_Controller_Numbers.html
@@ -0,0 +1,196 @@
+
+<html><head>
+<title>MIDI Standard Controller Numbers</title><style type="text/css"></style></head>
+<body>
+<center>
+<table border="4" cellspacing="3" cellpadding="1">
+<tbody><tr><th valign="center" colspan="3"><font size="+3">MIDI Controller Numbers</font></th>
+</tr><tr align="center"><td colspan="3">The table below presents a summary of the MIDI Standard Controller codes in decimal and hexadecimal (h)  form. </td></tr>
+
+<tr align="center">
+<td width="10%"><b>Decimal</b></td><td width="10%"><b>Hex</b></td><td align="left" width="80%"><b>Controller Name</b></td>
+</tr>
+<tr align="center">
+<td>0</td><td>00h</td><td align="left">Bank Select (Controller # 32 more commonly used)</td>
+</tr>
+
+<tr align="center">
+<td>1</td><td>01h</td><td align="left">Modulation Wheel</td>
+</tr>
+
+<tr align="center">
+<td>2</td><td>02h</td><td align="left">Breath Contoller</td>
+</tr>
+
+<tr align="center">
+<td>3</td><td>03h</td><td align="left">Undefined</td>
+</tr>
+
+<tr align="center">
+<td>4</td><td>04h</td><td align="left">Foot Controller</td>
+</tr>
+
+<tr align="center">
+<td>5</td><td>05h</td><td align="left">Portamento Time</td>
+</tr>
+
+<tr align="center">
+<td>6</td><td>06h</td><td align="left">Data Entry MSB</td>
+</tr>
+
+<tr align="center">
+<td>7</td><td>07h</td><td align="left">Main Volume</td>
+</tr>
+
+<tr align="center">
+<td>8</td><td>08h</td><td align="left">Balance</td>
+</tr>
+
+<tr align="center">
+<td>9</td><td>09h</td><td align="left">Undefined</td>
+</tr>
+
+<tr align="center">
+<td>10</td><td>0Ah</td><td align="left">Pan</td>
+</tr>
+
+<tr align="center">
+<td>11</td><td>0Bh</td><td align="left">0Ch</td>
+</tr>
+
+<tr align="center">
+<td>12</td><td>0Ch</td><td align="left">Effect Control 1</td>
+</tr>
+
+<tr align="center">
+<td>13</td><td>0Dh</td><td align="left">Effect Control 2</td>
+</tr>
+
+<tr align="center">
+<td>14-15</td><td>0E-0Fh</td><td align="left">Undefined</td>
+</tr>
+
+<tr align="center">
+<td>16-19</td><td>10-13h</td><td align="left">General Purpose Controllers (Nos. 1-4)</td>
+</tr>
+
+<tr align="center">
+<td>20-31</td><td>14-1Fh</td><td align="left">Undefined</td>
+</tr>
+
+<tr align="center">
+<td>32-63</td><td>20-3Fh</td><td align="left">LSB for Controllers 0-31 (rarely implemented)</td>
+</tr>
+
+<tr align="center">
+<td>64</td><td>40h</td><td align="left">Damper Pedal (Sustain) [Data Byte of 0-63=0ff, 64-127=On]</td>
+</tr>
+
+<tr align="center">
+<td>65</td><td>41h</td><td align="left">Portamento</td>
+</tr>
+
+<tr align="center">
+<td>66</td><td>42h</td><td align="left">Sostenuto</td>
+</tr>
+
+<tr align="center">
+<td>67</td><td>43h</td><td align="left">Soft Pedal</td>
+</tr>
+
+<tr align="center">
+<td>68</td><td>44h</td><td align="left">Legato Footswitch</td>
+</tr>
+
+<tr align="center">
+<td>69</td><td>45h</td><td align="left">Hold 2</td>
+</tr>
+
+<tr align="center">
+<td>70</td><td>46h</td><td align="left">Sound Controller 1 (default: Sound Variation)</td>
+</tr>
+
+<tr align="center">
+<td>71</td><td>47h</td><td align="left">Sound Controller 2 (default: Timbre/Harmonic Content)</td>
+</tr>
+<tr align="center">
+<td>72</td><td>48h</td><td align="left">Sound Controller 3 (default: Release Time)</td>
+</tr>
+<tr align="center">
+<td>73</td><td>49h</td><td align="left">Sound Controller 4 (default: Attack Time)</td>
+</tr>
+<tr align="center">
+<td>74</td><td>4Ah</td><td align="left">Sound Controller 5 (default: Brightness)</td>
+</tr>
+<tr align="center">
+<td>75-79</td><td>4B-4Fh</td><td align="left">Sound Controller 6-10 (no defaults)</td>
+</tr>
+<tr align="center">
+<td>80-83</td><td>50-53h</td><td align="left">General Purpose Controllers (Nos. 5-8)</td>
+</tr>
+<tr align="center">
+<td>84</td><td>54h</td><td align="left">Portamento Control</td>
+</tr>
+<tr align="center">
+<td>85-90</td><td>55-5Ah</td><td align="left">Undefined</td>
+</tr>
+<tr align="center">
+<td>91</td><td>5Bh</td><td align="left">Effects 1 Depth (previously External Effects Depth)</td>
+</tr>
+<tr align="center">
+<td>92</td><td>5Ch</td><td align="left">Effects 2 Depth (previously Tremolo Depth)</td>
+</tr>
+<tr align="center">
+<td>93</td><td>5Dh</td><td align="left">Effects 3 Depth (previously Chorus Depth)</td>
+</tr>
+<tr align="center">
+<td>94</td><td>5Eh</td><td align="left">Effects 4 Depth (previously Detune Depth)</td>
+</tr>
+<tr align="center">
+<td>95</td><td>5Fh</td><td align="left">Effects 5 Depth (previously Phaser Depth)</td>
+</tr>
+<tr align="center">
+<td>96</td><td>60h</td><td align="left">Data Increment</td>
+</tr>
+<tr align="center">
+<td>97</td><td>61h</td><td align="left">Data Decrement</td>
+</tr>
+<tr align="center">
+<td>98</td><td>62h</td><td align="left">Non-Registered Parameter Number LSB</td>
+</tr>
+<tr align="center">
+<td>99</td><td>63h</td><td align="left">Non-Registered Parameter Number LSB</td>
+</tr>
+<tr align="center">
+<td>100</td><td>64h</td><td align="left">Registered Parameter Number LSB</td>
+</tr>
+<tr align="center">
+<td>101</td><td>65h</td><td align="left">Registered Parameter Number MSB</td>
+</tr>
+<tr align="center">
+<td>102-120</td><td>66-78h</td><td align="left">Undefined</td>
+</tr>
+<tr align="center"><td colspan="3"><b><font size="+1">Channel Mode Messages</font></b></td></tr>
+<tr align="center">
+<td>121</td><td>79h</td><td align="left">Reset All Controllers</td>
+</tr>
+<tr align="center">
+<td>122</td><td>7Ah</td><td align="left">Local Control</td>
+</tr>
+<tr align="center">
+<td>123</td><td>7Bh</td><td align="left">All Notes Off</td>
+</tr>
+<tr align="center">
+<td>124</td><td>7Ch</td><td align="left">Omni Off</td>
+</tr>
+<tr align="center">
+<td>125</td><td>7Dh</td><td align="left">Omni On</td>
+</tr>
+<tr align="center">
+<td>126</td><td>7Eh</td><td align="left">Mono On (Poly Off)</td>
+</tr>
+<tr align="center">
+<td>127</td><td>7Fh</td><td align="left">Poly On (Mono Off)</td>
+</tr>
+</tbody></table>
+</body></html>
\ No newline at end of file
diff --git a/l2ork_addons/K12/midi_control-help.pd b/l2ork_addons/K12/midi_control-help.pd
new file mode 100644
index 000000000..55ce36598
--- /dev/null
+++ b/l2ork_addons/K12/midi_control-help.pd
@@ -0,0 +1,62 @@
+#N canvas 248 30 509 652 10;
+#X obj 244 233 cnv 15 447 141 empty empty empty 20 12 0 14 -233017
+-66577 0;
+#X obj 470 -236 preset_hub k12 %hidden% %node% 2 13 8 %preset% 0 440
+%preset% 1 440 %preset% 2 440 %preset% 3 440 %node% 2 2 14 %preset%
+0 100 %preset% 1 100 %preset% 2 72.093 %preset% 3 72.093 %node% 2 7
+5 %preset% 0 10 %preset% 1 20 %preset% 2 30 %preset% 3 40 %node% 2
+7 7 %preset% 0 60 %preset% 1 60 %preset% 2 30 %preset% 3 40 %node%
+2 2 28 %preset% 0 1 %preset% 1 1 %node% 2 8 8 %node% 2 9 8 %node% 2
+10 4 %preset% 0 1 %preset% 1 1 %node% 2 10 5 %preset% 0 5000 %preset%
+1 5000 %node% 2 11 6 %preset% 0 1 %preset% 1 1 %node% 2 13 6 %preset%
+0 1 %node% 2 13 5 %preset% 0 1 %node% 2 12 7 %preset% 0 60 %preset%
+1 60 %node% 2 11 7 %preset% 0 0 %preset% 1 90 %node% 2 13 7 %preset%
+0 127 %preset% 1 127 %node% 2 13 7 %node% 2 14 5 %preset% 0 1 %preset%
+1 1 %node% 2 14 6 %preset% 0 1 %preset% 1 1 %node% 2 15 0 %preset%
+0 10000 %preset% 1 10000 %node% 2 15 4 %preset% 0 0 %preset% 1 1 %node%
+2 16 3 %preset% 0 0 %preset% 1 0 %node% 2 16 19 %preset% 0 127 %preset%
+1 127;
+#X obj 231 593 K12/output;
+#N canvas 569 322 379 204 META 0;
+#X text 7 5 DESCRIPTION MIDI control works exclusively with the MIDI
+synth and allows configuring of instrument's properties on a specified
+channel (MIDI synth supports channels 1-16);
+#X text 7 61 INLET_0 Set control value (0-127);
+#X text 7 91 OUTLET_0 Connect to MIDI synth to issue control command
+on a specified channel;
+#X restore 649 667 pd META;
+#X obj 209 -215 cnv 3 501 3 empty empty empty 5 14 0 20 -260097 -191407
+0;
+#X obj 209 -243 cnv 15 501 28 empty empty MIDI/Control 5 14 0 20 -139274
+-262144 0;
+#X obj 680 -212 ggee/image @pd_extra/K12/icons/l2ork.png 0;
+#X obj 447 -182 cnv 15 250 99 empty empty empty 20 12 0 14 -233017
+-66577 0;
+#X obj 602 -177 K12/preset;
+#X obj 230 465 K12/midi_synth;
+#X obj 230 -56 K12/midi_note;
+#X obj 595 156 K12/math_number;
+#X obj 230 -161 K12/math_number;
+#X obj 336 -161 K12/math_number;
+#X obj 595 279 K12/midi_control;
+#X obj 595 -63 K12/logic_metronome;
+#X obj 595 49 K12/logic_counter;
+#X text 453 -131 Recall zeroth preset \, then compare with the first
+preset., f 24;
+#X obj 254 349 pddplink doc/MIDI_Standard_Controller_Numbers.html;
+#X text 253 240 MIDI control works exclusively with the MIDI synth
+object. It allows for changing of instrument's properties on a specified
+channel. The channel can be customized by changing channel value (1-16)
+on the object \, while the control number (0-127) can be passed using
+object's left inlet. For more info on possible MIDI control messages
+open the page below (please note that not all controls will work on
+all instruments):, f 55;
+#X connect 9 0 2 0;
+#X connect 9 1 2 0;
+#X connect 10 0 9 0;
+#X connect 11 0 14 0;
+#X connect 12 0 10 0;
+#X connect 13 0 10 1;
+#X connect 14 0 9 0;
+#X connect 15 0 16 0;
+#X connect 16 0 11 0;
diff --git a/l2ork_addons/K12/midi_control.pd b/l2ork_addons/K12/midi_control.pd
new file mode 100644
index 000000000..a05febca5
--- /dev/null
+++ b/l2ork_addons/K12/midi_control.pd
@@ -0,0 +1,27 @@
+#N canvas 385 201 480 270 10;
+#X obj 375 103 ggee/image @pd_extra/K12/objects/midi_control.png 1
+;
+#X obj 368 6 loadbang;
+#X obj 388 105 nbx 2 14 1 16 0 1 empty empty empty -7 -8 0 10 -262144
+-1 -1 1 256 3;
+#X obj 200 70 inlet;
+#X obj 200 241 outlet;
+#X obj 426 71 preset_node k12;
+#X obj 427 97 preset_node k12;
+#X obj 200 199 pack f f f;
+#X text 335 104 Channel:;
+#X obj 382 122 nbx 3 14 0 127 0 1 empty empty empty -4 -8 0 10 -262144
+-1 -1 0 256 3;
+#X text 335 121 Control:;
+#X msg 368 28 open @pd_extra/K12/objects/midi_control.png;
+#X msg 200 220 cc \$2 \$3 \$1;
+#X connect 1 0 11 0;
+#X connect 2 0 7 1;
+#X connect 3 0 7 0;
+#X connect 5 0 2 0;
+#X connect 6 0 9 0;
+#X connect 7 0 12 0;
+#X connect 9 0 7 2;
+#X connect 11 0 0 0;
+#X connect 12 0 4 0;
+#X coords 0 -1 1 1 89 89 2 330 71;
diff --git a/l2ork_addons/K12/midi_instrument-help.pd b/l2ork_addons/K12/midi_instrument-help.pd
new file mode 100644
index 000000000..048776a6a
--- /dev/null
+++ b/l2ork_addons/K12/midi_instrument-help.pd
@@ -0,0 +1,51 @@
+#N canvas 351 15 509 652 10;
+#X obj 244 134 cnv 15 447 102 empty empty empty 20 12 0 14 -233017
+-66577 0;
+#X obj 470 -236 preset_hub k12 %hidden% %node% 2 13 8 %preset% 0 440
+%preset% 1 440 %preset% 2 440 %preset% 3 440 %node% 2 2 14 %preset%
+0 100 %preset% 1 100 %preset% 2 72.093 %preset% 3 72.093 %node% 2 7
+5 %preset% 0 10 %preset% 1 20 %preset% 2 30 %preset% 3 40 %node% 2
+7 7 %preset% 0 60 %preset% 1 60 %preset% 2 30 %preset% 3 40 %node%
+2 2 28 %preset% 0 1 %preset% 1 1 %node% 2 8 8 %node% 2 9 8 %node% 2
+10 4 %preset% 0 1 %preset% 1 1 %node% 2 10 5 %preset% 0 250 %preset%
+1 250 %node% 2 11 6 %preset% 0 1 %preset% 1 1 %node% 2 13 6 %preset%
+0 1 %node% 2 13 5 %preset% 0 1 %node% 2 13 7 %preset% 0 127 %preset%
+1 127 %node% 2 12 7 %preset% 0 1 %preset% 1 15 %node% 2 15 7 %preset%
+0 127 %preset% 1 127 %node% 2 14 7 %preset% 0 60 %preset% 1 60;
+#X obj 231 463 K12/output;
+#N canvas 530 280 379 204 META 0;
+#X text 7 5 DESCRIPTION MIDI instrument works exclusively with the
+MIDI synth and allows configuring of the instrument on a specified
+channel (MIDI synth supports channels 1-16);
+#X text 7 91 OUTLET_0 Connect to MIDI synth to issue instrument change
+command on a specified channel;
+#X text 7 61 INLET_0 Set instrument number (1-128. default 1);
+#X restore 649 537 pd META;
+#X obj 209 -215 cnv 3 501 3 empty empty empty 5 14 0 20 -260097 -191407
+0;
+#X obj 209 -243 cnv 15 501 28 empty empty MIDI/Instrument 5 14 0 20
+-139274 -262144 0;
+#X obj 680 -212 ggee/image @pd_extra/K12/icons/l2ork.png 0;
+#X obj 447 -182 cnv 15 250 99 empty empty empty 20 12 0 14 -233017
+-66577 0;
+#X obj 602 -177 K12/preset;
+#X obj 230 335 K12/midi_synth;
+#X obj 230 34 K12/midi_note;
+#X obj 595 140 K12/midi_instrument;
+#X obj 595 57 K12/math_number;
+#X text 452 -131 Recall leftmost presetと start the example. Then
+\, try the second., f 23;
+#X obj 230 -161 K12/math_number;
+#X obj 336 -161 K12/math_number;
+#X text 253 141 MIDI instrument works exclusively with the MIDI synth
+object. It allows for changing of the instrument on a specified channel.
+The channel can be customized by changing channel value (1-16) on the
+object \, while the instrument number (1-128) can be passed using object's
+left inlet., f 55;
+#X connect 9 0 2 0;
+#X connect 9 1 2 0;
+#X connect 10 0 9 0;
+#X connect 11 0 9 0;
+#X connect 12 0 11 0;
+#X connect 14 0 10 0;
+#X connect 15 0 10 1;
diff --git a/l2ork_addons/K12/midi_instrument.pd b/l2ork_addons/K12/midi_instrument.pd
new file mode 100644
index 000000000..ad132991f
--- /dev/null
+++ b/l2ork_addons/K12/midi_instrument.pd
@@ -0,0 +1,23 @@
+#N canvas 319 273 480 253 10;
+#X obj 375 103 ggee/image @pd_extra/K12/objects/midi_instrument.png
+1;
+#X obj 368 6 loadbang;
+#X obj 190 71 inlet;
+#X obj 190 226 outlet;
+#X obj 359 118 nbx 2 14 1 16 0 1 empty empty Channel: -7 -8 0 10 -262144
+-1 -1 1 256 3;
+#X obj 190 184 pack f f;
+#X obj 229 71 preset_node k12;
+#X msg 190 205 pgmout \$2 \$1;
+#X msg 368 28 open @pd_extra/K12/objects/midi_instrument.png;
+#X obj 190 92 - 1;
+#X connect 1 0 8 0;
+#X connect 2 0 9 0;
+#X connect 4 0 5 1;
+#X connect 4 0 6 0;
+#X connect 5 0 7 0;
+#X connect 6 0 4 0;
+#X connect 7 0 3 0;
+#X connect 8 0 0 0;
+#X connect 9 0 5 0;
+#X coords 0 -1 1 1 89 89 2 330 71;
diff --git a/l2ork_addons/K12/midi_note-help.pd b/l2ork_addons/K12/midi_note-help.pd
new file mode 100644
index 000000000..0d94ffa62
--- /dev/null
+++ b/l2ork_addons/K12/midi_note-help.pd
@@ -0,0 +1,51 @@
+#N canvas 96 21 502 652 10;
+#X obj 224 -61 cnv 15 469 101 empty empty empty 20 12 0 14 -233017
+-66577 0;
+#X obj 470 -236 preset_hub k12 %hidden% %node% 2 13 8 %preset% 0 440
+%preset% 1 440 %preset% 2 440 %preset% 3 440 %node% 2 2 14 %preset%
+0 100 %preset% 1 100 %preset% 2 72.093 %preset% 3 72.093 %node% 2 7
+5 %preset% 0 10 %preset% 1 20 %preset% 2 30 %preset% 3 40 %node% 2
+7 7 %preset% 0 60 %preset% 1 67 %preset% 2 30 %preset% 3 40 %node%
+2 2 28 %preset% 0 1 %preset% 1 1 %node% 2 8 8 %node% 2 9 8 %node% 2
+10 4 %preset% 0 1 %preset% 1 1 %node% 2 10 5 %preset% 0 250 %preset%
+1 2000 %node% 2 11 6 %preset% 0 1 %preset% 1 1 %node% 2 14 6 %preset%
+0 1 %node% 2 14 5 %preset% 0 1 %node% 2 13 7 %preset% 0 127 %preset%
+1 80 %node% 2 12 7 %node% 2 17 7 %node% 2 15 7 %preset% 0 60 %preset%
+1 67 %node% 2 14 7 %preset% 0 127 %preset% 1 80 %node% 2 15 7 %preset%
+0 60 %preset% 1 67;
+#X obj 231 433 K12/output;
+#N canvas 540 290 379 204 META 0;
+#X text 7 5 DESCRIPTION MIDI note works exclusively with the MIDI synth
+object and sends note on and off messages;
+#X text 7 53 INLET_0 Enter pitch (0-127);
+#X text 7 79 INLET_0 Enter loudness (0-127 \, default 127);
+#X text 7 110 OUTLET_0 Connect to MIDI synth to create a note;
+#X restore 649 507 pd META;
+#X obj 209 -215 cnv 3 501 3 empty empty empty 5 14 0 20 -260097 -191407
+0;
+#X obj 209 -243 cnv 15 501 28 empty empty MIDI/Note 5 14 0 20 -139274
+-262144 0;
+#X obj 680 -212 ggee/image @pd_extra/K12/icons/l2ork.png 0;
+#X obj 445 -183 cnv 15 253 102 empty empty empty 20 12 0 14 -233017
+-66577 0;
+#X obj 602 -177 K12/preset;
+#X obj 230 275 K12/midi_synth;
+#X obj 230 -56 K12/midi_note;
+#X obj 258 154 K12/midi_instrument;
+#X obj 258 71 K12/math_number;
+#X text 453 -130 Recall 0th presetと start the example \, then try
+preset 1, f 23;
+#X obj 336 -158 K12/math_number;
+#X obj 230 -158 K12/math_number;
+#X text 327 -53 MIDI note issues notes to the soundfont player (MIDI
+synth). You can specify pitch (left inlet \, 0-127) \, loudness (right
+inlet \, 0-127 \, by default set to 127) \, and inside the object you
+can specify duration of each note in milliseconds (default 250ms or
+1/4 of a second)., f 59;
+#X connect 9 0 2 0;
+#X connect 9 1 2 0;
+#X connect 10 0 9 0;
+#X connect 11 0 9 0;
+#X connect 12 0 11 0;
+#X connect 14 0 10 1;
+#X connect 15 0 10 0;
diff --git a/l2ork_addons/K12/midi_note.pd b/l2ork_addons/K12/midi_note.pd
new file mode 100644
index 000000000..64a49f697
--- /dev/null
+++ b/l2ork_addons/K12/midi_note.pd
@@ -0,0 +1,40 @@
+#N canvas 424 56 444 353 10;
+#X obj 375 103 ggee/image @pd_extra/K12/objects/midi_note.png 1;
+#X obj 368 6 loadbang;
+#X obj 387 98 nbx 2 14 1 16 0 1 empty empty empty -7 -8 0 10 -262144
+-1 -1 1 256 3;
+#X obj 198 70 inlet;
+#X obj 426 71 preset_node k12;
+#X obj 427 97 preset_node k12;
+#X text 340 97 Channel:;
+#X obj 347 129 nbx 5 14 1 1e+37 0 1 empty empty empty -4 -8 0 10 -262144
+-1 -1 250 256 1;
+#X msg 368 28 open @pd_extra/K12/objects/midi_note.png;
+#X text 347 112 Duration:;
+#X obj 198 313 outlet;
+#X obj 198 202 t l l, f 18;
+#X msg 198 181 \$2 \$1;
+#X obj 303 274 list append 0;
+#X obj 198 160 pack f f f;
+#X obj 285 70 inlet;
+#X obj 303 223 pipe f f 250;
+#X obj 303 248 pack 0 0;
+#X obj 198 223 list append 127;
+#X connect 1 0 8 0;
+#X connect 2 0 14 1;
+#X connect 3 0 14 0;
+#X connect 4 0 2 0;
+#X connect 5 0 7 0;
+#X connect 7 0 16 2;
+#X connect 8 0 0 0;
+#X connect 11 0 18 0;
+#X connect 11 1 16 0;
+#X connect 12 0 11 0;
+#X connect 13 0 10 0;
+#X connect 14 0 12 0;
+#X connect 15 0 18 1;
+#X connect 16 0 17 0;
+#X connect 16 1 17 1;
+#X connect 17 0 13 0;
+#X connect 18 0 10 0;
+#X coords 0 -1 1 1 89 89 2 330 71;
diff --git a/l2ork_addons/K12/midi_synth-help.pd b/l2ork_addons/K12/midi_synth-help.pd
new file mode 100644
index 000000000..6ee14f72b
--- /dev/null
+++ b/l2ork_addons/K12/midi_synth-help.pd
@@ -0,0 +1,66 @@
+#N canvas 47 14 502 652 10;
+#X obj 493 -238 preset_hub k12 %hidden% %node% 2 13 8 %preset% 0 440
+%preset% 1 440 %preset% 2 440 %preset% 3 440 %node% 2 2 14 %preset%
+0 100 %preset% 1 100 %preset% 2 72.093 %preset% 3 72.093 %node% 2 7
+5 %preset% 0 10 %preset% 1 20 %preset% 2 30 %preset% 3 40 %node% 2
+7 7 %preset% 0 60 %preset% 1 67 %preset% 2 30 %preset% 3 40 %node%
+2 2 28 %preset% 0 1 %preset% 1 1 %node% 2 8 8 %node% 2 9 8 %node% 2
+10 4 %preset% 0 1 %preset% 1 1 %node% 2 10 5 %preset% 0 250 %preset%
+1 2000 %node% 2 11 6 %preset% 0 1 %preset% 1 1 %node% 2 14 6 %preset%
+0 1 %node% 2 14 5 %preset% 0 1 %node% 2 14 7 %preset% 0 127 %preset%
+1 80 %node% 2 12 7 %node% 2 15 7 %node% 2 17 7 %preset% 0 60 %preset%
+1 67 %node% 2 13 7 %preset% 0 127 %preset% 1 80 %node% 2 15 7 %preset%
+0 60 %preset% 1 67 %node% 2 16 5 %preset% 0 1 %preset% 1 1 %node% 2
+16 6 %preset% 0 0 %preset% 1 0;
+#X obj 224 179 cnv 15 473 219 empty empty empty 20 12 0 14 -233017
+-66577 0;
+#X obj 231 423 K12/output;
+#N canvas 520 270 379 204 META 0;
+#X text 7 53 INLET_0 Connect MIDI note to play a note \, MIDI instrument
+to change instrument \, and MIDI control to change instrument properties
+(e.g. modulation);
+#X text 7 110 OUTLET_0 Outputs audio of synth's left channel;
+#X text 7 5 DESCRIPTION MIDI synth plays soundfonts. By default it
+loads a GM (General MIDI) soundfont;
+#X text 8 139 OUTLET_1 Outputs audio of synth's right channel (you
+can mix it with the left if you are not interested in panning the sound)
+;
+#X restore 649 497 pd META;
+#X obj 209 -215 cnv 3 501 3 empty empty empty 5 14 0 20 -260097 -191407
+0;
+#X obj 209 -243 cnv 15 501 28 empty empty MIDI/Synth 5 14 0 20 -139274
+-262144 0;
+#X obj 680 -212 ggee/image @pd_extra/K12/icons/l2ork.png 0;
+#X obj 445 -183 cnv 15 253 102 empty empty empty 20 12 0 14 -233017
+-66577 0;
+#X obj 602 -177 K12/preset;
+#X obj 230 185 K12/midi_synth;
+#X obj 230 -56 K12/midi_note;
+#X obj 342 27 K12/midi_instrument;
+#X obj 342 -56 K12/math_number;
+#X text 453 -130 Recall 0th presetと start the example \, then try
+preset 1, f 23;
+#X obj 336 -158 K12/math_number;
+#X obj 454 -56 K12/math_number;
+#X obj 454 27 K12/midi_control;
+#X obj 230 -158 K12/math_number;
+#X text 327 187 MIDI synth plays soundfonts (sf2 files). By default
+it offers GM (General MIDI) sound bank. For its input it receives messages
+exclusively from MIDI note (note on/off information) \, MIDI instrument
+(change instrument) \, and MIDI control (change instrument properties)
+objects. It outputs left (left outlet) and right (right outlet) audio
+channels \, thus allowing for sounds to be panned to different speakers
+\, or (as is the case in this demo) mixed to the same speaker.You
+can also open other custom sf2 soundfonts by clicking no the "open"
+button. Such custom choices can be saved using the preset object.For
+a complete list of General MIDI sounds see:;
+#X obj 328 372 pddplink doc/GM_instrument_list.html;
+#X connect 9 0 2 0;
+#X connect 9 1 2 0;
+#X connect 10 0 9 0;
+#X connect 11 0 9 0;
+#X connect 12 0 11 0;
+#X connect 14 0 10 1;
+#X connect 15 0 16 0;
+#X connect 16 0 9 0;
+#X connect 17 0 10 0;
diff --git a/l2ork_addons/K12/midi_synth.pd b/l2ork_addons/K12/midi_synth.pd
new file mode 100644
index 000000000..c81cf4593
--- /dev/null
+++ b/l2ork_addons/K12/midi_synth.pd
@@ -0,0 +1,32 @@
+#N canvas 383 211 453 369 10;
+#X obj 375 103 ggee/image @pd_extra/K12/objects/midi_synth.png 1;
+#X obj 368 6 loadbang;
+#X msg 368 28 open @pd_extra/K12/objects/midi_synth.png;
+#X obj 277 319 fluid~ /usr/share/sounds/sf2/FluidR3_GM.sf2;
+#X obj 277 351 outlet~;
+#X obj 532 351 outlet~;
+#X obj 196 109 inlet;
+#X symbolatom 358 222 30 0 0 0 - - -, f 30;
+#X obj 423 194 preset_node k12;
+#X obj 380 108 bng 15 250 50 0 empty empty empty 19 8 0 10 -262144
+-1 -1;
+#X obj 358 194 openpanel;
+#X msg 358 243 init \$1;
+#X msg 196 184 prog \$1 \$2;
+#X obj 196 163 route pgmout, f 14;
+#X text 348 107 Open:;
+#X connect 1 0 2 0;
+#X connect 2 0 0 0;
+#X connect 3 0 4 0;
+#X connect 3 1 5 0;
+#X connect 6 0 13 0;
+#X connect 7 0 11 0;
+#X connect 7 0 8 0;
+#X connect 8 0 7 0;
+#X connect 9 0 10 0;
+#X connect 10 0 7 0;
+#X connect 11 0 3 0;
+#X connect 12 0 3 0;
+#X connect 13 0 12 0;
+#X connect 13 1 3 0;
+#X coords 0 -1 1 1 89 89 2 330 71;
diff --git a/l2ork_addons/K12/preset-help.pd b/l2ork_addons/K12/preset-help.pd
index 121374d42..28f9c4a10 100755
--- a/l2ork_addons/K12/preset-help.pd
+++ b/l2ork_addons/K12/preset-help.pd
@@ -1,26 +1,21 @@
-#N canvas 252 110 502 470 10;
-#X obj 25 52 cnv 15 481 274 empty empty empty 20 12 0 14 -233017 -66577
+#N canvas 383 39 502 580 10;
+#X obj 25 52 cnv 15 481 369 empty empty empty 20 12 0 14 -233017 -66577
 0;
 #X obj 138 -34 preset_hub k12 %hidden% %node% 2 5 9 %node% 2 7 8 %preset%
 1 2 %preset% 0 1 %preset% 2 3 %preset% 3 4 %node% 2 9 7 %node% 2 3
-8 %node% 2 8 7 %node% 2 4 7;
+8 %node% 2 8 7 %node% 2 4 7 %preset% 0 10 %preset% 1 20 %preset% 2
+30 %preset% 3 1337;
 #X obj 17 -8 cnv 3 501 3 empty empty empty 5 14 0 20 -260097 -191407
 0;
 #X obj 31 57 K12/preset;
-#X obj 31 345 K12/math_number;
-#X text 140 229 In this example \, we have stored four presets that
-have different numbers in this Math Number object. Click on recall
-in the Preset object and notice that the number changes. Then \, change
-the number in the number box and click on one of the store boxes. When
-you click on the recall box for that store \, you will see that it
-recalls the number you set.;
+#X obj 31 445 K12/math_number;
 #N canvas 172 259 450 300 META 0;
 #X text 13 6 DESCRIPTION Use this to save different presets in your
 program. Click on a store box to store a preset in that slot \, and
 click on a recall box to recall that preset;
 #X text 14 56 INLET_0 Values 0-3 will recall presets 0-3;
 #X text 13 77 INLET_1 Values 0-3 will store presets 0-3;
-#X restore 462 406 pd META;
+#X restore 462 515 pd META;
 #X text 141 56 The preset object allows you save all the specific settings
 of your objects and recall them later. For example you can save the
 number in a number box. You store the values by clicking one of the
@@ -35,3 +30,14 @@ their values.;
 #X obj 17 -37 cnv 15 501 28 empty empty Preset 5 14 0 20 -139274 -262144
 0;
 #X obj 487 -4 ggee/image @pd_extra/K12/icons/l2ork.png 0;
+#X text 140 229 In this example \, we have stored four presets that
+have different numbers in this Math Number object. Click on recall
+in the Preset object and notice that the number changes. Then \, change
+the number in the number box and click on one of the store boxes. When
+you click on the recall box for that store \, you will see that it
+recalls the number you set.IMPORTANT! When recalling presets \, values
+will be distributed to objects in the order they were created. This
+could mean that the pitch (for instance) will reach a MIDI instrument
+before loudness and as such \, the loudness change will only affect
+the next note. You need to be mindful of this when creating your patch.
+, f 59;
diff --git a/pd/src/pd.tk b/pd/src/pd.tk
index 3f187bb58..d2ca76d26 100644
--- a/pd/src/pd.tk
+++ b/pd/src/pd.tk
@@ -464,6 +464,11 @@ proc pdtk_enable_k12_mode {extra_dir} {
 	image create photo i.instr_sustained1 -file $extra_dir/K12/icons/instr_sustained1.png
 	image create photo i.instr_sustained2 -file $extra_dir/K12/icons/instr_sustained2.png
 
+	image create photo i.midi_synth -file $extra_dir/K12/icons/midi_synth.png
+	image create photo i.midi_note -file $extra_dir/K12/icons/midi_note.png
+	image create photo i.midi_instrument -file $extra_dir/K12/icons/midi_instrument.png
+	image create photo i.midi_control -file $extra_dir/K12/icons/midi_control.png
+
 	image create photo i.fx_filter -file $extra_dir/K12/icons/fx_filter.png
 	image create photo i.fx_multitap -file $extra_dir/K12/icons/fx_multitap.png
 	image create photo i.fx_reverb -file $extra_dir/K12/icons/fx_reverb.png
@@ -2500,7 +2505,7 @@ proc pdtk_k12_show_sound_icons {name} {
 	$name.k12frame.datasound.sound configure -image i.sound_on
 	catch {
 		pack forget $name.k12frame.wii $name.k12frame.wii2 $name.k12frame.arduino $name.k12frame.math_1 $name.k12frame.math_2 $name.k12frame.math_3 $name.k12frame.logic $name.k12frame.other
-		pack $name.k12frame.signal_1 $name.k12frame.signal_2 $name.k12frame.signal_3 $name.k12frame.instr $name.k12frame.fx $name.k12frame.output -side top -expand 0 -fill x
+		pack $name.k12frame.signal_1 $name.k12frame.signal_2 $name.k12frame.signal_3 $name.k12frame.instr $name.k12frame.midi $name.k12frame.fx $name.k12frame.output -side top -expand 0 -fill x
 	}
 }
 
@@ -2931,6 +2936,26 @@ proc pdtk_canvas_new {name width height geometry editable} {
 		pdtk_k12panel_standardkeybindings $name.k12frame.instr.b_instr_sustained1
 		pdtk_k12panel_standardkeybindings $name.k12frame.instr.b_instr_sustained2
 
+		# ---------------------------------- MIDI INSTRUMENTS ------------------------------------
+		match_linux_wm [list frame $name.k12frame.midi -relief flat]
+		match_linux_wm [list button $name.k12frame.midi.b_midi_synth -image i.midi_synth \
+			-command [concat put_K12_objects $name midi_synth]]
+		match_linux_wm [list button $name.k12frame.midi.b_midi_note -image i.midi_note \
+			-command [concat put_K12_objects $name midi_note]]
+		match_linux_wm [list button $name.k12frame.midi.b_midi_instrument -image i.midi_instrument \
+			-command [concat put_K12_objects $name midi_instrument]]
+		match_linux_wm [list button $name.k12frame.midi.b_midi_control -image i.midi_control \
+			-command [concat put_K12_objects $name midi_control]]
+		pack $name.k12frame.midi.b_midi_synth $name.k12frame.midi.b_midi_note $name.k12frame.midi.b_midi_instrument $name.k12frame.midi.b_midi_control -side left -expand 0 -padx 1 -pady 1
+		setTooltip $name.k12frame.midi.b_midi_synth "MIDI Synth: create a synthesizer with up to 128 unique sounds"
+		setTooltip $name.k12frame.midi.b_midi_note "MIDI Note: connect this to MIDI synth to issue note on and off commands"
+		setTooltip $name.k12frame.midi.b_midi_instrument "MIDI Instrument: connect this to MIDI synth to issue instrument change commands"
+		setTooltip $name.k12frame.midi.b_midi_control "MIDI Control: connect this to MIDI synth to change instrument properties"
+		pdtk_k12panel_standardkeybindings $name.k12frame.midi.b_midi_synth
+		pdtk_k12panel_standardkeybindings $name.k12frame.midi.b_midi_note
+		pdtk_k12panel_standardkeybindings $name.k12frame.midi.b_midi_instrument
+		pdtk_k12panel_standardkeybindings $name.k12frame.midi.b_midi_control
+
 		# ---------------------------------- F/X -----------------------------------------
 		match_linux_wm [list frame $name.k12frame.fx -relief flat]
 		match_linux_wm [list button $name.k12frame.fx.b_fx_filter -image i.fx_filter \
-- 
GitLab