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 Key Manual Toggle Velocity|2 Key Manual Staccato Toggle Velocity|3 Key Manual Vibrato Toggle Velocity|4 Left Manual Toggle Velocity|5 Left Manual 16 foot Vibrato Velocity|6 Bellows Shake 8 foot Velocity|7 Nail Glissando on Key Manual|8 Bellows Strokes|9 Air Noises|10 Stop Noises|11 Key + Left Manual Toggle Velocity|12 Key Manual Staccato + Left Manual Toggle Velocity|13 Key Manual Vibrato + Left Manual Toggle Velocity|14 A Cassotto 8 foot Velocity|15 A Cassotto Staccato 8 foot Velocity|16 A Cassotto Vibrato 8 foot Velocity|17 In Cassotto 8 foot Velocity|18 In Cassotto Staccato 8 foot Velocity|19 In Cassotto Vibrato 8 foot Velocity|20 Piccolo 4 foot Velocity|21 Piccolo 4 foot Staccato Velocity|22 Bassoon 16 foot Velocity|23 Bassoon 16 foot Staccato Velocity|24 Bassoon 16 foot Vibrato Velocity|25 Violin 8 + 8 Velocity|26 Violin 8 + 8 Staccato Velocity|27 Violin 8 + 8 Vibrato Velocity|28 Musette 8 + 8 + 4 Velocity|29 Musette 8 + 8 + 4 Staccato Velocity|30 Accord 8 + 8 + 16 Velocity|31 Accord 8 + 8 + 16 Staccato Velocity|32 Accord 8 + 8 + 16 Vibrato Velocity|33 Bandon 8 + 16 Velocity|34 Bandon 8 + 16 Staccato Velocity|35 Bandon 8 + 16 Vibrato Velocity|36 Organ 16 + 4 Velocity|37 Organ 16 + 4 Staccato Velocity|38 Oboe I 8 A Cassotto + 4 Velocity|39 Oboe I 8 A Cassotto + 4 Staccato Velocity|40 Oboe II 8 In Cassotto + 4 Velocity|41 Oboe II 8 In Cassotto + 4 Staccato Velocity|42 Harmon I 16 + 8 A Cassotto + 4 Velocity|43 Harmon I 16 + 8 A Cassotto + 4 Staccato Velocity|44 Harmon II 16 + 8 In Cassotto + 4 Velocity|45 Harmon II 16 + 8 In Cassotto + 4 Staccato Velocity|46 Master 4 + 8 + 8 + 16 Velocity|47 Master 4 + 8 + 8 + 16 Staccato Velocity|48 Left Manual 8 foot Velocity|49 Left Manual 16 foot Velocity|50 Left Manual 8 + 16 foot Velocity|51 Triple Shake 8 foot A Cassotto 16T Sync|52 Triple Shake 8 foot In Cassotto 16T Sync|53 Triple Shake 4 foot 16T Sync|54 Triple Shake 16 foot 16T Sync|55 Violin Triple Shake 8 + 8 foot 16T Sync|56 Bandon Triple Shake 8 + 16 foot 16T Sync|57 Organ Triple Shake 4 + 16 foot 16T Sync|58 Oboe Triple Shake 8 + 4 foot 16T Sync||")
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)
