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 Velocity MW Shape|3 Staccato Velocity MW Shape|4 Mouthpiece Tones Velocity MW Shape|5 Straight Mute MW|6 Straight Mute Staccato Velocity MW Shape|7 Cup Mute MW|8 Bucket Mute MW|9 Plunger Slow Velocity MW Shape|10 Plunger wah-wah MW|11 Plunger Velocity wah-wah MW|12 Voice Breathing Velocity|13 Drop Down Velocity MW Shape|14 Harmonics Glissando Up Velocity MW Shape|15 Metal + Valve Sounds Velocity|16 Air Noises Velocity MW Shape|17 Undefined Tones 1 Velocity MW Shape|18 Undefined Tones 2 Velocity MW Shape|19 Undefined Tones 3 Velocity MW Shape|20 Open Velocity + MW inverted|21 Open Velocity|22 Open Velocity Bell MW|23 Triple Tongue 16T|24 Straight Mute Velocity|25 Cup Mute Velocity|26 Bucket Mute Velocity|27 Open Velocity x MW Flutter Tongue|28 Staccato Velocity|29 With Accent Velocity|30 Mouthpiece Tones Velocity|31 Straight Mute Staccato Velocity|32 Voice Breathing MW|33 Drop Down MW|34 Harmonics Glissando MW|35 Air Noises Velocity|36 Undefined Tones 2 Velocity|37 Flutter Tongue MW|38 Crescendo|39 Vibrato MW|40 Vibrato Velocity|41 Vibrato Velocity + MW inverted|42 Secco Velocity|43 Portato Velocity|44 Pseudo Tuba Open Velocity + MW inverted|45 Pseudo Tuba Staccato + Marcato Velocity|46 Pseudo Horn Open Velocity + MW inverted|47 Pseudo Horn Staccato + Marcato 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)
