1ardour { 2 ["type"] = "dsp", 3 name = "AVL Drumkit MIDI Map", 4 category = "Utility", 5 license = "MIT", 6 author = "Ardour Community", -- based on MIDI Note Mapper by Alby Musaelian 7 description = [[Map MIDI notes to drum-kit pcs of 'Black Pearl' or 'Red Zeppelin' AVL drumkit plugins. Unmapped notes are ignored. In case of duplicate assignments the later one is preferred.]] 8} 9 10OFF_NOTE = -1 11 12function dsp_ioconfig () 13 return { { midi_in = 1, midi_out = 1, audio_in = 0, audio_out = 0}, } 14end 15 16function dsp_params () 17 local avldrums = { 18 [36] = "Kick Drum", 19 [37] = "Snare Side Stick", 20 [38] = "Snare Center", 21 [39] = "Hand Clap", 22 [40] = "Snare Edge", 23 [41] = "Floor Tom Center", 24 [42] = "Closed HiHat", 25 [43] = "Floor Tom Edge", 26 [44] = "Pedal HiHat", 27 [45] = "Tom Center", 28 [46] = "Semi-Open HiHat", 29 [47] = "Tom Edge", 30 [48] = "Swish HiHat", 31 [49] = "Crash Cymbal 1 (left)", 32 [50] = "Crash Cymbal 1 Choked", 33 [51] = "Ride Cymbal Tip", 34 [52] = "Ride Cymbal Choked", 35 [53] = "Ride Cymbal Bell", 36 [54] = "Tambourine", 37 [55] = "Splash Cymbal", 38 [56] = "Cowbell", 39 [57] = "Crash Cymbal 2 (right)", 40 [58] = "Crash Cymbal 2 Choked", 41 [59] = "Ride Cymbal Shank", 42 [60] = "Crash Cymbal 3 (large Paiste)", 43 [61] = "Maracas" 44 } 45 46 local map_scalepoints = {} 47 map_scalepoints["None"] = OFF_NOTE 48 49 for note=0,127 do 50 local name = ARDOUR.ParameterDescriptor.midi_note_name(note) 51 map_scalepoints[string.format("%03d (%s)", note, name)] = note 52 end 53 54 local map_params = {} 55 56 local i = 1 57 for note, name in pairs (avldrums) do 58 map_params[i] = { 59 ["type"] = "input", 60 name = name, 61 min = -1, 62 max = 127, 63 default = note, 64 integer = true, 65 enum = true, 66 scalepoints = map_scalepoints 67 } 68 i = i + 1 69 end 70 71 return map_params 72end 73 74function dsp_run (_, _, n_samples) 75 assert (type(midiin) == "table") 76 assert (type(midiout) == "table") 77 local cnt = 1; 78 79 function tx_midi (time, data) 80 midiout[cnt] = {} 81 midiout[cnt]["time"] = time; 82 midiout[cnt]["data"] = data; 83 cnt = cnt + 1; 84 end 85 86 -- build translation table 87 local translation_table = {} 88 local ctrl = CtrlPorts:array() 89 for i = 1, 26 do 90 if not (ctrl[i] == OFF_NOTE) then 91 translation_table[ctrl[i]] = 35 + i 92 end 93 end 94 95 -- for each incoming midi event 96 for _,b in pairs (midiin) do 97 local t = b["time"] -- t = [ 1 .. n_samples ] 98 local d = b["data"] -- midi-event data 99 local event_type 100 if #d == 0 then event_type = -1 else event_type = d[1] >> 4 end 101 102 if (#d == 3) and (event_type == 9 or event_type == 8 or event_type == 10) then 103 -- Do the mapping - 2 is note byte for these types 104 d[2] = translation_table[d[2]] or OFF_NOTE 105 if not (d[2] == OFF_NOTE) then 106 tx_midi (t, d) 107 end 108 else 109 tx_midi (t, d) 110 end 111 end 112end 113