form caption("SimpleSampler") size(800, 400), guiMode("queue"), colour(255, 255, 255), pluginId("def1")
keyboard bounds(12, 292, 780, 95)
soundfiler bounds(327, 7, 458, 194), channel("soundfiler1")
;image bounds(8, 6, 76, 62), channel("sampleSlot1"), outlineThickness(3), corners(10), outlineColour("black")
;button bounds(24, 40, 46, 22), text("Play"), channel("sampleSlotPlay1")
;label bounds(24, 16, 46, 18), text("1"), fontColour("black"), channel("sampleSlotLabel1")
;rslider bounds(338, 206, 60, 60) range(0, 2, 1, 1, 0.001), channel("sampleSlotFreq1"), text("Freq")
-n -d -+rtmidi=NULL -M0 -m0d --midi-key=4 --midi-velocity-amp=5
; Initialize the global variables.
ksmps = 32
nchnls = 2
0dbfs = 1
;instrument will be triggered by keyboard widget
instr SampleSlot
iSlotNumber = p4
iX = p5
iY = p6
SImageCode sprintf "image bounds(%d, %d, 76, 62), channel(\"sampleSlot%d\"), outlineThickness(3), corners(10), outlineColour(\"black\")", iX, iY, iSlotNumber
SButtonCode sprintf "button bounds(%d, %d, 46, 22), text(\"Play\"), channel(\"sampleSlotPlay%d\")", iX+16, iY+34, iSlotNumber
SLabelCode sprintf "label bounds(%d, %d, 46, 18), text(\"%d\"), fontColour(\"black\"), channel(\"sampleSlotLabel%d\")", iX+16, iY+10, iSlotNumber, iSlotNumber
SFreqCode sprintf "rslider bounds(338, 206, 60, 60) range(0, 2, 1, 1, 0.001), channel(\"sampleSlotFreq%d\"), text(\"Freq\"), visible(0)", iSlotNumber
cabbageCreate SImageCode
cabbageCreate SButtonCode
cabbageCreate SLabelCode
cabbageCreate SFreqCode
SFileChannel sprintf "sampleSlot%d_file", iSlotNumber
SChannel sprintf "sampleSlot%d", iSlotNumber
SLabelChannel sprintf "sampleSlotLabel%d", iSlotNumber
SPlayChannel sprintf "sampleSlotPlay%d", iSlotNumber
kBounds[] cabbageGet SChannel, "bounds"
kX chnget "MOUSE_X"
kY chnget "MOUSE_Y"
kMouseDownImage, kImageTrig cabbageGetValue SChannel
kMouseDownLabel, kLabelTrig cabbageGetValue SLabelChannel
if kLabelTrig == 1 || kImageTrig == 1 then
cabbageSet 1, "soundfiler1", "file", chnget:S(SFileChannel)
event "i", "ShowFreqSlider", 0, .1, iSlotNumber
endif
SFile, kFileChanged cabbageGet "LAST_FILE_DROPPED"
SCurrentWidget, kWidgetChanged cabbageGet "CURRENT_WIDGET"
if kFileChanged == 1 then
if kX > kBounds[0] && kX < kBounds[0]+kBounds[2] && kY > kBounds[1] && kY < kBounds[1]+kBounds[3] then
cabbageSet kFileChanged, "soundfiler1", "file", SFile
chnset SFile, SFileChannel
endif
endif
kButton, kButtonTrig cabbageGetValue SPlayChannel
if kButtonTrig == 1 then
event "i", "ShowFreqSlider", 0, .1, iSlotNumber
cabbageSet 1, "soundfiler1", "file", chnget:S(SFileChannel)
event "i", 1, 0, 1, 60+iSlotNumber-1
endif
endin
instr ShowFreqSlider
iSlotNumber = p4
iCnt = 0
while iCnt < 16 do
SFreqChannel sprintf "sampleSlotFreq%d", iCnt
if iCnt == iSlotNumber then
cabbageSet SFreqChannel, "visible(1)"
else
cabbageSet SFreqChannel, "visible(0)"
endif
iCnt += 1
od
endin
instr 1
print p4
SFileChannel sprintf "sampleSlot%d_file", (p4-60)+1
SFreqChannel sprintf "sampleSlotFreq%d", (p4-60)+1
kDummyEnv madsr .01, 0, 1, filelen(chnget:S(SFileChannel))*5
a1 diskin2 chnget:S(SFileChannel), chnget:i(SFreqChannel), 0, 0
outs, a1, a1
endin
i"SampleSlot" 0 z 1 8 6
i"SampleSlot" 0 z 2 88 6
i"SampleSlot" 0 z 3 168 6
i"SampleSlot" 0 z 4 248 6
i"SampleSlot" 0 z 5 8 72
i"SampleSlot" 0 z 6 88 72
i"SampleSlot" 0 z 7 168 72
i"SampleSlot" 0 z 8 248 72
i"SampleSlot" 0 z 9 8 138
i"SampleSlot" 0 z 10 88 138
i"SampleSlot" 0 z 11 168 138
i"SampleSlot" 0 z 12 248 138
i"SampleSlot" 0 z 13 8 204
i"SampleSlot" 0 z 14 88 204
i"SampleSlot" 0 z 15 168 204
i"SampleSlot" 0 z 16 248 204
;i"SampleSlot" 0 z 2
;causes Csound to run for about 7000 years...
f0 z