Hi @rorywalsh, the solution works perfectly all ambience .wavs in 1 instrument thank you. Having issues now trying to get a second instrument to work. I dont understand enough to see why the second two instruments are still calling for ambience.wavs. Again thanks for the help, any you could give would be fantastic
;========================================================================================================================================================================================================================
; UX Section
;========================================================================================================================================================================================================================
; Define the main window with a title, size, GUI mode, and plugin ID
form caption("Tabletop Audio Controller") size(834, 748), guiMode("queue"), pluginId("def1")
; Used to Define the Background Image and its boundaries
image bounds(0, 0, 834, 748) channel("image1") file("BG1.jpg")
; Create the first set of controls for the Ambience
groupbox bounds(2, 2, 830, 110), text(“Ambience”) channel(“groupbox1”) colour(89, 0, 0, 255) outlineColour(255, 255, 255, 255) fontColour(255, 255, 255, 255) alpha(0.6)
button bounds(100, 22, 80, 80) channel(“playButton1”) text(“Tavern”, “Tavern”)
button bounds(194, 22, 80, 80) channel(“playButton2”) text(“Town”, “Town”)
button bounds(286, 22, 80, 80) channel(“playButton3”) text(“Cave”, “Cave”)
button bounds(378, 22, 80, 80) channel(“playButton4”) text(“Forest”, “Forest”)
button bounds(10, 22, 80, 80) channel(“stopButton1”) text(“Stop”, “Stop”) colour:1(147, 0, 0, 255) colour:0(147, 0, 0, 255)
hslider bounds(460, 22, 370, 40) channel(“volumeSlider1”) range(0, 1, 0.5, 1, 0.001) textColour(0, 0, 0, 255) trackerColour(210, 178, 0, 255)
; Create the second set of controls for the Music
groupbox bounds(2, 118, 830, 110), text(“Music”) channel(“groupbox2”) colour(67, 0, 89, 255) outlineColour(255, 255, 255, 255) fontColour(255, 255, 255, 255) alpha(0.6)
button bounds(100, 138, 80, 80) channel(“playButton5”) text(“Relaxed”, “Relaxed”)
button bounds(194, 138, 80, 80) channel(“playButton6”) text(“Combat”, “Combat”)
button bounds(286, 138, 80, 80) channel(“playButton7”) text(“Tense”, “Tense”)
button bounds(10, 138, 80, 80) channel(“stopButton2”) text(“Stop”, “Stop”) colour:1(147, 0, 0, 255) colour:0(147, 0, 0, 255)
hslider bounds(380, 138, 450, 40) channel(“volumeSlider2”) range(0, 1, 0.5, 1, 0.001) textColour(0, 0, 0, 255) trackerColour(210, 0, 166, 255)
; Set Csound options: -n for no sound output file, -d for no display of performance information
-n -d
;=======================================================================================================================================================================================================================
; Initialize global variables
;=======================================================================================================================================================================================================================
sr = 44100 ; Set the sample rate to 44100 Hz
ksmps = 64 ; Set the control rate to 64 samples
nchnls = 2 ; Set the number of audio channels to 2 (stereo)
0dbfs = 1 ; Set the maximum amplitude to 1
;========================================================================================================================================================================================================================
; Ambience Instrument Section
;========================================================================================================================================================================================================================
instr Ambience
; Generate the filename for the Ambience based on the button pressed
SFilname sprintf “ambience%d.wav”, p4
a1, a2 diskin2 SFilname, 1, 0, 1
kVol chnget “volumeSlider1”
outs a1 * kVol, a2 * kVol
endin
instr AmbiencePlay
SPlayChannel sprintf “playButton%d”, p4
kButton, kButtonTrig cabbageGetValue SPlayChannel
if (kButtonTrig == 1) then
if ( kButton == 1 ) then
turnoff2 1.1, 0, 0
turnoff2 1.2, 0, 0
turnoff2 1.3, 0, 0
turnoff2 1.4, 0, 0
event "i", 1+(p4*.1), 0, -1, p4
else
turnoff2 1+(p4*.1), 0, 0
endif
endif
kStopButton1, kStopButtonTrig cabbageGetValue "stopButton1"
if (kStopButtonTrig == 1) then
turnoff2 1.1, 0, 0
turnoff2 1.2, 0, 0
turnoff2 1.3, 0, 0
turnoff2 1.4, 0, 0
endif
endin
;========================================================================================================================================================================================================================
; Music Instrument Section
;========================================================================================================================================================================================================================
instr Music
; Generate the filename for the Music based on the button pressed
SFilname sprintf “music%d.wav”, p4
a1, a2 diskin2 SFilname, 1, 0, 1
kVol chnget “volumeSlider2”
outs a1 * kVol, a2 * kVol
endin
instr MusicPlay
SPlayChannel sprintf “playButton%d”, p4
kButton, kButtonTrig cabbageGetValue SPlayChannel
if (kButtonTrig == 1) then
if ( kButton == 1 ) then
turnoff2 2.1, 0, 0
turnoff2 2.2, 0, 0
turnoff2 2.3, 0, 0
event "i", 2+(p4*.1), 0, -1, p4
else
turnoff2 2+(p4*.1), 0, 0
endif
endif
kStopButton2, kStopButtonTrig cabbageGetValue "stopButton2"
if (kStopButtonTrig == 1) then
turnoff2 2.1, 0, 0
turnoff2 2.2, 0, 0
turnoff2 2.3, 0, 0
endif
endin
i "AmbiencePlay" 0 86400 1
i "AmbiencePlay" 0 86400 2
i "AmbiencePlay" 0 86400 3
i "AmbiencePlay" 0 86400 4
i "MusicPlay" 0 86400 5
i "MusicPlay" 0 86400 6
i "MusicPlay" 0 86400 7