selected = false
muted = false
midiChan = 0

gfx.init("Xsample",1,1)

gfx.x = gfx.mouse_x
gfx.y = gfx.mouse_y

input = gfx.showmenu("1 Conga + Bongos|2 Cabaza + Maracas + Bell Rattle|3 Sound Bowl + Tibet Bowl + Anvil + Bell Rattle|4 Lotus Flute|5 Japanese Birdflute|6 Bird + Whistle - Percussion Toys|7 Frog - Percussion Toy|8 Horn|9 Whistle + Train Whistle|10 Metronome|11 Friction Drums|12 Rainmaker|13 Scraper Velocity MW Shape|14 Talk Drum Velocity MW Shape|15 Watergongs Velocity MW Shape|16 Hi-Hat Velocity MW Shape|17 Steel Plates Velocity MW Shape|18 Steel Plates Damped Velocity MW Shape|19 Steel Plates in water Velocity MW Shape|20 Kalimba Velocity x MW open - closed manual vibrato|21 Kalimba Vibrato Velocity|22 Kazoo Velocity MW Shape|23 Air Hose - Percussion Toy|24 Cowbells Velocity MW Shape|25 Cowbells Damped Velocity MW Shape|26 Cowbell Rolls Velocity RS CC2 MW Shape|27 Stones + Nails Velocity MW Release|28 Claps Velocity|29 Snips Velocity|30 Pasteboard Rattle Velocity MW Release|31 Rattle + Ratchet Velocity MW Shape|32 Vellum Drum|33 Map 1 - Percussion Toys|34 Map 2 - Scraper + Ratchet + Rattles + Air Hose|35 Map 3 - Rainmaker + Cabaza + Maracas||")
if input >= 0 then 

function main() 
  take = reaper.MIDIEditor_GetTake(reaper.MIDIEditor_GetActive())
  if take == nil then return end
  item = reaper.GetMediaItemTake_Item(take)
  pos = reaper.GetCursorPosition() 
  ppq = reaper.MIDI_GetPPQPosFromProjTime(take, pos)
  
  MSB = 0
  LSB = 0
  PC  = 0
  
  if input ~= 0 then
  
  reaper.MIDI_InsertCC(
    take, 
    selected,
    muted,
    ppq,
    0xB0,-- midi CC
    midiChan,
    0, -- controller #0: Bank Select MSB
    input-1 -- MSB value
  )
  reaper.MIDI_InsertCC(
    take, 
    selected,
    muted,
    ppq,
    0xB0,-- midi CC
    midiChan,
    32, -- controller #32: Bank Select LSB
    0 -- LSB value
  )
  reaper.MIDI_InsertCC(
    take, 
    selected,
    muted,
    ppq,
    0xC0,-- Program Change
    midiChan,
    PC, -- program change value
    0
  )
  end
  reaper.UpdateItemInProject(item)   
end
end

script_title = "Xsample Acoustic Instruments"
reaper.Undo_BeginBlock()
main()
reaper.Undo_EndBlock(script_title, 0)
