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 Senza Vibrato MW|2 Natural Vibrato MW|3 Staccato Velocity MW Shape|4 Staccato 2 MW Shape|5 Flutter Tongue MW|6 Slap Tongue Velocity|7 Glissando Undefined MW Shape|8 Undefined Tones Velocity|9 Key Noises Velocity|10 Multiphonics Velocity|11 Air Noises Velocity|12 Crescendo|13 Senza Vibrato Velocity|14 Natural Vibrato Velocity|15 Senza Vibrato + Flutter Tongue Velocity X MW|16 Flutter Tongue Velocity|17 Senza Vibrato Velocity + MW inverted|18 Triple Tongue 16T|19 Staccato Velocity|20 With Accent Velocity|21 Glissando Undefined MW|22 Multiphonics MW|23 Air Noises MW|24 Vibrato MW|25 Vibrato Velocity|26 Vibrato Velocity + MW inverted|27 Secco Velocity|28 Portato Velocity|29 Flutter Tongue Velocity + MW inverted|30 Pseudo Contrabass Velocity + MW inverted|31 Pseudo Contrabass Staccato Velocity|32 Pseudo Clarinet Velocity + MW inverted|33 Pseudo Clarinet 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)
