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 Manual 1-1 MW 1+2+5 -- Tutti|2 Manual 2-3 MW 1+2+3+4 -- Tutti|3 Manual 3-1 MW 1+3+4 -- Tutti|4 Manual 4-1 MW 1+2 -- Tutti|5 Pedal 1 MW 1+2+3 -- Tutti |6 Manual 3 MW  Cresc - Breath Swell|7 Master Tutti MW + Pedal Tutti|8 Motor On - Off -- Cluster + Noises|9 Manual 1-1 MW M 3-4 + M 4-3 |10 Manual 1-3 MW M 1-2 + M 3-6 Foot Tremulant|11 Manual 1-4 MW M 4-1 + M 3-4 Foot Tremulant|12 Manual 1-1+5 MW M 3-5|13 Manual 1-1+2+5 MW M 2-3 + M 3-5 |14 Manual 1-Tutti MW M 3-Tutti + M 4-Tutti|15 Manual 2-1 MW M 4-1 + M 1-2|16 Manual 2-1+2 MW M 4-1|17 Manual 2-3 MW M 1-5 + M 3-4|18 Manual 2-5 MW M 2-3 + M 3-5|19 Manual 2-6 MW M 3-3 + M 1-3|20 Manual 2-1+2+3+4 MW M 3-1+3+4 or M 1-1+2+5|21 Manual 2-Tutti MW M 3-Tutti or M 1-Tutti|22 Manual 3-1 MW M 3-4 or M 4-1|23 Manual 3-1+2 MW M 2-2|24 Manual 3-3 MW M 1-5 + M 2-3|25 Manual 3-3+4 MW M 2-4|26 Manual 3-6 MW M 3-1 + M 4-2 Foot Tremulant|27 Manual 3-1+3+4 MW M 4-1+2 or M 1-1+2+5|28 Manual 3-Tutti MW M 2-4 + M 4-Tutti|29 Manual 4-1 MW M 1-1 + M 4-3|30 Manual 4-3 MW M 3-1 + M 3-2 Foot Tremulant|31 Manual 4-1+2 MW M 1-5 + M 2-4|32 Manual 4-Tutti MW M 1-3 + M 3-5|33 Pedal 1 MW M 3-1 + M 3-6|34 Pedal 1+3 MW M 4-1 + M 3-4|35 Pedal 2 MW M 4-3 or M 4-2|36 Pedal 4 MW M 1-3 + M 3-5|37 Pedal 1+2+3 MW M 4-3 + M 1-4|38 Pedal Tutti MW M 1-Tutti or M 2-Tutti|39 Manual 2-2|40 Manual 2-1 + M 3-1 + M 3-2|41 Manual 4 MW Cresc - Breath Swell|42 Manual 3-1+3 + M 2-2|43 Pedal 2+1||")
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)
