From d099dc044970743edd5eced66e910d5c22c640d2 Mon Sep 17 00:00:00 2001 From: gesellkammer Date: Sat, 23 Nov 2024 12:04:58 +0100 Subject: [PATCH] tests --- .github/workflows/test.yml | 2 +- ctcsound7/api7.py | 21 +++++++++++++-------- test/actions-test1.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 test/actions-test1.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 570a356..3dd2cbb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: diff --git a/ctcsound7/api7.py b/ctcsound7/api7.py index 1e858ec..749b10c 100644 --- a/ctcsound7/api7.py +++ b/ctcsound7/api7.py @@ -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. @@ -1731,7 +1731,8 @@ 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: @@ -1739,8 +1740,7 @@ def event(self, kind: str, pfields: _t.Sequence[float] | np.ndarray, block=True) 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: """ @@ -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. @@ -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) diff --git a/test/actions-test1.py b/test/actions-test1.py new file mode 100644 index 0000000..e785746 --- /dev/null +++ b/test/actions-test1.py @@ -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...")