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 Open MW|2 Flutter Tongue MW|3 Staccato Velocity MW Shape|4 Accent Velocity MW Shape|5 Mute MW|6 Mute Staccato Velocity MW Shape|7 Crescendo|8 Voice Breathing Third x Octave MW|9 Voice Breathing Undefined Tones Velocity MW Shape|10 Air Noises Velocity MW Shape|11 Vacuum Noises - white + Air Noises - black Velocity |12 Slap Tongue Velocity|13 Mouthpiece Strokes Velocity|14 Body Strokes Velocity MW Shape|15 Valve Noises Velocity MW Shape|16 Undefined Tones 1 Velocity MW Shape|17 Undefined Tones 2 Velocity MW Shape|18 Open Velocity + MW inverted|19 Open Velocity|20 Open Velocity Bell MW|21 Open Velocity x MW Flutter Tongue|22 Mute Velocity Bell MW|23 Mute Velocity|24 Triple Tongue 16T|25 Staccato Velocity|26 Accent Velocity|27 Mute Staccato Velocity|28 Voice Breathing Octave MW|29 Air Noises Velocity|30 Valve Noises Velocity|31 Undefined Tones 2 Velocity|32 Vibrato MW|33 Vibrato Velocity|34 Vibrato Velocity + MW inverted|35 Secco Velocity|36 Portato Velocity|37 Flutter Tongue Velocity + MW inverted|38 Pseudo Deep Tuba Velocity + MW inverted|39 Pseudo Deep Tuba Staccato Velocity|40 Pseudo Trombone Velocity + MW inverted|41 Pseudo Trombone Staccato Velocity||")
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)
