spell-music / csound-expression

Haskell Framework for Electronic Music
319 stars 31 forks source link

Csound error when using `Csound.Control.Evt.every` #95

Open rvl opened 1 month ago

rvl commented 1 month ago

Hi, I was following Quickstart - Event streams and noticed an error when using Csound.Control.Evt.every.

This is my code:

import Csound.Base

notes1, notes2 :: Evt D
notes1 = repeatE 330 $ metroE 4
notes2 = every 0 [2] notes1

playNotes :: Evt D -> IO ()
playNotes = dacBy dacOpts . sched instr . withDur 0.25
  where
    dacOpts :: Options
    dacOpts = setGain 0.6 <> setTrace

    instr :: D -> SE Sig
    instr x = return $ 0.5 * osc (sig x)
  1. playNotes notes1 works as expected.
  2. playNotes notes2 results in an error from Csound

The error message is:

ghci> playNotes notes2
UnifiedCSD:  /tmp/tmp.csd
error:  Unable to find opcode entry for 'fillarray' with matching argument types:

Found: a[] fillarray kk
       ararr10 fillarray kr2 ...
Line: 64
 from file /tmp/tmp.csd (1),Parsing failed due to syntax errors
Stopping on parser failure
cannot compile orchestra
end of score.          overall amps:      0.0
       overall samples out of range:        0
1 errors in performance
Elapsed time at end of performance: real: 0.002s, CPU: 0.002s

This is the contents of /tmp/tmp.csd for notes1:

<CsoundSynthesizer>

<CsOptions>

--nodisplays --output=dac

</CsOptions>

<CsInstruments>

sr = 44100
ksmps = 64
nchnls = 1
0dbfs = 1.0
gkrggBpmVar init 110.0
giPort init 1
opcode FreePort, i, 0
xout giPort
giPort = giPort + 1
endop

instr 23
endin

instr 22
event_i "i", 21, 604800.0, 1.0e-2
endin

instr 21
ir0 = 20
ir1 = 0.0
turnoff2 ir0, ir1, ir1
ir3 = 19
turnoff2 ir3, ir1, ir1
ir6 = 18
turnoff2 ir6, ir1, ir1
exitnow
endin

instr 20
arl0 init 0.0
ar1 subinstr 19
ir3 = 1.0
ir4 = 0.0
ir5 = 90.0
ir6 = 100.0
ar2 upsamp k(ir3)
ar3 compress ar1, ar2, ir4, ir5, ir5, ir6, ir4, ir4, 0.0
ar1 = (ar3 * 0.6)
arl0 = ar1
ar1 = arl0
out ar1
endin

instr 19
krl0 init 10.0
ir1 FreePort
kr1 = 4.0
kr2 metro kr1
ir6 = 18
ir9 = 330.0
if (kr2 == 1.0) then
    krl0 = 2.0
    kr1 = 0.0
    kr2 = 0.25
    event "i", ir6, kr1, kr2, ir9, ir1
endif
S14 sprintf "p1_%d", ir1
ar0 chnget S14
chnclear S14
arl1 init 0.0
arl1 = ar0
ar0 = arl1
out ar0
kr1 = krl0
S29 sprintf "alive_%d", ir1
chnset kr1, S29
endin

instr 18
arl0 init 0.0
kr0 = 1.0
kr1 = p4
ar1 oscil3 kr0, kr1, 2
ar2 = (0.5 * ar1)
arl0 = ar2
ar1 = arl0
S9 sprintf "p1_%d", p5
chnmix ar1, S9
S12 sprintf "alive_%d", p5
kr0 chnget S12
if (kr0 < -10.0) then
    turnoff
endif
kr1 = (kr0 - 1.0)
chnset kr1, S12
endin

</CsInstruments>

<CsScore>

f2 0 8192 10 1.0

f0 604800.0

i 23 0.0 -1.0
i 22 0.0 -1.0
i 20 0.0 -1.0

</CsScore>

</CsoundSynthesizer>

This is the contents of /tmp/tmp.csd for notes2:

<CsoundSynthesizer>

<CsOptions>

--nodisplays --output=dac

</CsOptions>

<CsInstruments>

sr = 44100
ksmps = 64
nchnls = 1
0dbfs = 1.0
gkrggBpmVar init 110.0
giPort init 1
opcode FreePort, i, 0
xout giPort
giPort = giPort + 1
endop

instr 23
endin

instr 22
event_i "i", 21, 604800.0, 1.0e-2
endin

instr 21
ir0 = 20
ir1 = 0.0
turnoff2 ir0, ir1, ir1
ir3 = 19
turnoff2 ir3, ir1, ir1
ir6 = 18
turnoff2 ir6, ir1, ir1
exitnow
endin

instr 20
arl0 init 0.0
ar1 subinstr 19
ir3 = 1.0
ir4 = 0.0
ir5 = 90.0
ir6 = 100.0
ar2 upsamp k(ir3)
ar3 compress ar1, ar2, ir4, ir5, ir5, ir6, ir4, ir4, 0.0
ar1 = (ar3 * 0.6)
arl0 = ar1
ar1 = arl0
out ar1
endin

instr 19
krl0 init 10.0
ir1 FreePort
krl1 init 0.0
kr2 = 4.0
kr3 metro kr2
kr2 = 1.0
kr4 = 0.0
ararr10[] fillarray kr2, kr4
ir14 = 18
ir16 = 330.0
if (kr3 == 1.0) then
    kr2 = krl1
    ar0 = ararr10[kr2]
    kr3 downsamp ar0
    if (kr3 == 1.0) then
        krl0 = 2.0
        kr3 = 0.25
        event "i", ir14, kr4, kr3, ir16, ir1
    endif
    kr3 = (kr2 + 1.0)
    kr2 = kr3
    if (kr2 < 2.0) then
        kr23 = kr3
    else
        kr23 = 0.0
    endif
    krl1 = kr23
endif
S28 sprintf "p1_%d", ir1
ar0 chnget S28
chnclear S28
arl2 init 0.0
arl2 = ar0
ar0 = arl2
out ar0
kr2 = krl0
S43 sprintf "alive_%d", ir1
chnset kr2, S43
endin

instr 18
arl0 init 0.0
kr0 = 1.0
kr1 = p4
ar1 oscil3 kr0, kr1, 2
ar2 = (0.5 * ar1)
arl0 = ar2
ar1 = arl0
S9 sprintf "p1_%d", p5
chnmix ar1, S9
S12 sprintf "alive_%d", p5
kr0 chnget S12
if (kr0 < -10.0) then
    turnoff
endif
kr1 = (kr0 - 1.0)
chnset kr1, S12
endin

</CsInstruments>

<CsScore>

f2 0 8192 10 1.0

f0 604800.0

i 23 0.0 -1.0
i 22 0.0 -1.0
i 20 0.0 -1.0

</CsScore>

</CsoundSynthesizer>

Versions:

Thanks

anton-k commented 1 month ago

Thanks for report!