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 Vibrato MW|2 Senza Vibrato MW|3 Staccato Velocity 1 MW Shape|4 Staccato Velocity 2 MW Shape|5 Flutter Tongue MW|6 Secco Velocity|7 Key Noises x Secco Velocity|8 Short Velocity|9 Accent Velocity MW Shape|10 Whistle Tones Velocity|11 Key Noises Velocity|12 Multiphonics + Undefined Tones Velocity|13 Harmonics Layout 1 Velocity|14 Tones with sssss Velocity MW Shape|15 Airy Tones Velocity MW Shape|16 Jet Whistle Velocity|17 Vibrato Velocity|18 Senza Vibrato Velocity|19 Flutter Tongue Velocity|20 Vibrato Velocity + MW inverted|21 Senza Vibrato Velocity + MW inverted|22 Vibrato + Flutter Tongue Velocity X MW|23 Senza Vibrato + Flutter Tongue Velocity X MW|24 Vibrato + Senza Vibrato MW 2 dimensional X CC2|25 Staccato 1 + Key Noises X Secco Velocity MW|26 Staccato 2 + Key Noises X Secco Velocity MW|27 Triple Tongue 16T|28 Staccato Velocity|29 Accent Velocity|30 Multiphonics MW|31 Mouthpiece Tones MW|32 Airy Tones MW|33 Tones with sssss MW|34 Undefined Tones Velocity|35 Crescendo Espressivo|36 Crescendo|37 Portato Velocity|38 Vibrato to Senza Vibrato Velocity|39 Senza Vibrato to Vibrato Velocity|40 Vibrato - Senza Vibrato Velocity X MW|41 Flutter Tongue Velocity + MW inverted|42 Pseudo Alto Velocity + MW inverted|43 Pseudo Alto 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)
