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 Velocity|2 Senza Vibrato Velocity|3 Spiccato Velocity + Marcato MW Switch|4 Tremolo Velocity + MW inverted|5 Harmonics Velocity|6 Pizzicato Velocity|7 Col Legno Velocity|8 Bartok Pizzicato Velocity|9 Tremolo Sul Ponticello|10 Sul Ponticello|11 Finger Velocity|12 Con Sordino Vibrato Velocity|13 Con Sordino Senza Vibrato Velocity|14 Sul Ponticello Short Velocity|15 Gettato Velocity|16 Glissandi Velocity|17 Body Strokes Velocity|18 Harmonics Glissandi Velocity|19 Undefined Tones Velocity|20 Slides Up Velocity Release Switch|21 Slides Down Velocity Release Switch|22 Pizzicato Vibrato Velocity|23 Vibrato Velocity + MW inverted|24 Senza Vibrato Velocity + MW inverted|25 Vibrato Velocity alternate|26 Vibrato MW|27 Senza Vibrato MW|28 Con Sordino Vibrato MW|29 Vibrato Velocity Bell MW|30 Senza Vibrato Velocity Bell MW|31 Tremolo Sul Ponticello MW|32 Sul Ponticello MW|33 Harmonics Glissandi MW|34 Glissandi MW|35 With Accent Velocity|36 Staccato Velocity MW Spiccato|37 Tremolo MW|38 Con Sordino Senza Vibrato MW|39 Harmonics MW|40 Spiccato Velocity|41 Marcato 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)
