Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gesellkammer committed Nov 23, 2024
1 parent dd85d39 commit d099dc0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
- name: test
run: |
cd test
python test1.py
python actions-test1.py -o actions-test1-${{ runner.os }}-${{ matrix.csound-branch }}.wav
#- uses: actions/upload-artifact@v3
# with:
Expand Down
21 changes: 13 additions & 8 deletions ctcsound7/api7.py
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,7 @@ def setOutputChannelCallback(self, function: _t.Callable) -> None:
self._outputChannelCallback = CHANNELFUNC(function)
libcsound.csoundSetOutputChannelCallback(self.cs, self._outputChannelCallback)

def event(self, kind: str, pfields: _t.Sequence[float] | np.ndarray, block=True):
def event(self, kind: str, pfields: _t.Sequence[float] | np.ndarray, block=True) -> None:
"""
Send a new event.
Expand All @@ -1731,16 +1731,16 @@ def event(self, kind: str, pfields: _t.Sequence[float] | np.ndarray, block=True)
block: if True, the operation is blocking. Otherwise it is
performed asynchronously
.. note:: this method does not exist in csound 6. For backwards compatibility
use :meth:`Csound.scoreEvent` or :meth:`Csound.scoreEventAsync`
"""
eventtype = _scoreEventToTypenum.get(kind)
if eventtype is None:
raise ValueError(f"Invalid event kind, get {kind}, expected one of {_scoreEventToTypenum.keys()}")
p = np.asarray(pfields, dtype=MYFLT)
ptr = p.ctypes.data_as(ct.POINTER(MYFLT))
n_fields = ct.c_int32(p.size)
libcsound.csoundEvent(self.cs, ct.c_int32(eventtype), ptr, n_fields,
ct.c_int32(not block))
libcsound.csoundEvent(self.cs, ct.c_int32(eventtype), ptr, n_fields, ct.c_int32(not block))

def scoreEvent(self, kind: str, pfields: _t.Sequence[float] | np.ndarray) -> int:
"""
Expand Down Expand Up @@ -1897,17 +1897,22 @@ def tableArgs(self, tableNum: int) -> np.ndarray | None:
def scoreTime(self) -> float:
"""Returns the current score time.
Returns:
current time, in seconds
The return value is the time in seconds since the beginning of
performance.
performance. This can be used to schedule events at absolute times
.. seealso:: :meth:`Csound.currentTimeSamples`
"""
return libcsound.csoundGetScoreTime(self.cs)

def isScorePending(self) -> bool:
"""Tells whether Csound score events are performed or not.
Independently of real-time MIDI events (see set_score_pending()).
Independently of real-time MIDI events (see :py:meth:`setScorePending`).
"""
return libcsound.csoundIsScorePending(self.cs) != 0
return bool(libcsound.csoundIsScorePending(self.cs))

def setScorePending(self, pending: bool) -> None:
"""Sets whether Csound score events are performed or not.
Expand Down Expand Up @@ -1946,7 +1951,7 @@ def setScoreOffsetSeconds(self, time: float) -> None:
def rewindScore(self) -> None:
"""Rewinds a compiled Csound score.
It is rewinded to the time specified with set_score_offset_seconds().
It is rewinded to the time specified with :py:meth:`setScoreOffsetSeconds()`.
"""
libcsound.csoundRewindScore(self.cs)

Expand Down
35 changes: 35 additions & 0 deletions test/actions-test1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import ctcsound7 as ct
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('-o', '--outfile', default='test.wav')
parser.add_argument('-d', '--dur', default=10, type=int)
args = parser.parse_args()

cs = ct.Csound()

cs.setOption(f"-o{args.outfile}")
cs.compileOrc(r'''
0dbfs = 1
ksmps = 64
nchnls = 2
instr 1
kchan init -1
kchan = (kchan + metro:k(1)) % nchnls
if changed:k(kchan) == 1 then
println "Channel: %d", kchan + 1
endif
asig = pinker() * 0.2
outch kchan + 1, asig
endin
''')

cs.scoreEvent('i', [1, 0, args.dur])
cs.scoreEvent('e', [0, args.dur])
cs.start()

while not cs.performKsmps():
print(".", end='')
pass
print("\nFinished...")

0 comments on commit d099dc0

Please sign in to comment.