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 Ensemble A Velocity|2 Ensemble A Staccato Velocity|3 Ensemble B Velocity|4 Ensemble B Staccato Velocity|5 Flutter Tongue Velocity|6 Straight Mute Velocity|7 Straight Mute Staccato Velocity|8 Cup Mute Velocity|9 Mouthpiece Tones Velocity|10 Voice Breathing Velocity|11 Valve Noises Velocity|12 Air Noises Velocity|13 Glissandi Velocity|14 Undefined Tones Velocity|15 Ensemble A MW|16 Ensemble B MW|17 Flutter Tongue MW|18 Straight Mute MW|19 Cup Mute MW|20 Ensemble A Velocity + MW inverted|21 Ensemble B Velocity + MW inverted|22 Ensemble A Velocity Bell MW|23 Ensemble B Velocity Bell MW|24 Plunger Velocity + MW inverted|25 Ensemble A With Accent Velocity|26 Ensemble B With Accent Velocity|27 Mouthpiece Tones MW|28 Glissandi MW|29 Voice Breathing MW||")
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)
