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|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 + Undefined Tones|27 Pizzicato Harmonics|28 Natural Harmonics|29 Sul Ponticello Short Velocity|30 Spiccato Sul Ponticello Velocity|31 Gettato Velocity MW Shape|32 Col Legno Gettato MW Shape|33 Spotted MW Shape|34 Talking Bow|35 Rosin Plucks|36 Pizzicato Glissando Velocity|37 Harmonics Glissandi|38 Harmonics Glissandi Con Sordino|39 Spiccato Tempo Sync 16T|40 Flautando Fragile Velocity|41 Senza Vibrato MW|42 Vibrato MW|43 Vibrato + Senza Vibrato MW 2 dimensional X CC2|44 Uncommon Articulation Delay 16|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 Harmonics MW|54 Con Sordino Senza Vibrato MW|55 Con Sordino Vibrato MW|56 Marcato Staccato Velocity|57 Gettato Velocity|58 Col Legno Gettato Velocity|59 Harmonics Tremolo MW|60 Body Strokes Velocity|61 Dead Notes Velocity|62 Pizzicato in Peg Box Velocity|63 Pizzicato Behind Bridge Velocity|64 Bow Percussion Velocity|65 Harmonics Glissando MW|66 Harmonics Glissando Tremolo MW|67 Harmonics Glissando Con Sordino MW|68 Harmonics Glissando Con Sordino Tremolo MW|69 Natural Harmonics sul B MW|70 Natural Harmonics sul E MW|71 Natural Harmonics sul A MW|72 Natural Harmonics sul D MW|73 Natural Harmonics sul G MW|74 Pizzicato Harmonics sul B MW|75 Pizzicato Harmonics sul E MW|76 Pizzicato Harmonics sul A MW|77 Pizzicato Harmonics sul D MW|78 Pizzicato Harmonics sul G MW|79 With Accent Velocity|80 Staccato Velocity MW Spiccato|81 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)
