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 Velocity + MW inverted|2 Spiccato Pizzicato Col Legno MW Switch|3 Tremolo Velocity + MW inverted|4 Tremolo SP + Sul Ponticello MW|5 Harmonics + Glissando Velocity|6 Con Sordino Vibrato + Senza Vibrato Velocity MW|7 Vibrato Velocity + MW inverted|8 Spiccato + Marcato CC2 MW Shape|9 Pizzicato + Bartok Pizzicato CC2 MW Shape|10 Col Legno + Finger CC2 MW Shape|11 Vibrato Velocity Ensemble 3 Voices|12 Spiccato Velocity Ensemble 3 Voices|13 Pizzicato Velocity Ensemble 3 Voices|14 Tremolo Velocity Ensemble 3 Voices|15 Bartok Pizzicato Velocity Ensemble 3 Voices|16 Col Legno Velocity Ensemble 3 Voices|17 Con Sordino Vibrato Velocity Ensemble 3 Voices|18 Finger Velocity Ensemble 3 Voices|19 Tremolo Sul Ponticello Velocity Ensemble 3 Voices|20 Sul Ponticello Velocity Ensemble 3 Voices|21 Undefined tones A Ensemble|22 Tuning Peg + Tailpiece Pluck + Undefined Tones Ensemble|23 Random Pizzicato Garden MW Shape|24 Unpredictable Ensemble|25 Undefined tones A|26 Tuning Peg + Tailpiece Pluck + Effects|27 Harmonics Glissando|28 Glissandi|29 Natural Harmonics|30 Natural Harmonics Con Sordino|31 Sul Ponticello Short Velocity|32 Gettato Velocity|33 Pizzicato Vibrato Velocity|34 Pizzicato Vibrato Ensemble 3 Voices|35 Pizzicato Sul Ponticello Velocity|36 Pizzicato alla Doublebass Velocity|37 Col Legno Gettato Velocity|38 Spiccato Tempo Sync 16T|39 Senza Vibrato MW|40 Vibrato MW|41 Vibrato + Senza Vibrato MW 2 dimensional X CC2|42 Uncommon Articulation Delay 16|43 Harmonics Trill Velocity|44 Artificial Harmonics Con Sordino Velocity|45 Tremolo MW|46 Spiccato Velocity|47 Pizzicato Velocity|48 Col Legno Velocity|49 Bartok Pizzicato Velocity|50 Finger Velocity|51 Tremolo Sul Ponticello MW|52 Sul Ponticello MW|53 Artificial Harmonics MW|54 Con Sordino Senza Vibrato MW|55 Con Sordino Vibrato MW|56 Marcato Short Velocity|57 Artificial Harmonics Con Sordino MW|58 Artificial Harmonics Trill MW|59 Flautando MW|60 Spiccato Con Sordino Velocity|61 Spiccato Sul Ponticello Velocity|62 Staccato Velocity MW Spiccato|63 Harmonics Tremolo MW|64 Pizzicato Con Sordino Velocity|65 Body Strokes Velocity|66 Pizzicato in Peg Box Velocity|67 Pizzicato Behind Bridge Velocity|68 Rosin Noises Velocity|69 Tailpiece Bowed MW|70 Spike Bowed MW|71 Pizzicato Spike-String Holder-Bridge Velocity|72 Bow Scratch MW|73 Natural Harmonics sul C MW|74 Natural Harmonics sul G MW|75 Natural Harmonics sul D MW|76 Natural Harmonics sul A MW|77 Natural Harmonics Con Sordino sul C MW|78 Natural Harmonics Con Sordino sul G MW|79 Natural Harmonics Con Sordino sul D MW|80 Natural Harmonics Con Sordino sul A MW|81 Glissandi MW|82 Glissandi Con Sordino MW|83 Harmonics Glissando MW|84 Harmonics Glissando Con Sordino MW|85 Harmonics Glissando Tremolo MW|86 With Accent Velocity|87 Portato 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)
