[Csnd] How do I use the scoreEvent method in CTCsound

Hi all,

Can anyone give me some tips on how to use the scorEvent method in the Csound API with Python? I’ve read the documentation for the method, and this article

Csound Journal (csounds.com)

To figure out how to use it, but so far, I haven’t had any luck with getting it to work.

I’ve tried things like

Import ctcsound

Cs = ctcsound.Csound()

Cs.compileOrc(orchestra)

Cs.setOption(”-odac”)

Cs.start()

Cs.scoreEvent(”i”, [1, 0, 5])

Cs.perform()

Cs.stop()

Import ctcsound

Cs = ctcsound.Csound()

Cs.compileOrc(orchestra)

Cs.setOption(”-odac”)

Cs.start()

Cs.perform()

Cs.scoreEvent(”i”, [1, 0, 5])

Cs.stop()

Any help would be much appreciated.

Kind regards,

Susanne

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Hi!

The article uses parenthesis instead of brackets, does it make any difference?

Tarmo

N, 9. november 2023 10:46 Susanne Pedersen <sp@susanne-pedersen.dk> kirjutas:

Hi all,

Can anyone give me some tips on how to use the scorEvent method in the Csound API with Python? I’ve read the documentation for the method, and this article

Csound Journal (csounds.com)

To figure out how to use it, but so far, I haven’t had any luck with getting it to work.

I’ve tried things like

Import ctcsound

Cs = ctcsound.Csound()

Cs.compileOrc(orchestra)

Cs.setOption(”-odac”)

Cs.start()

Cs.scoreEvent(”i”, [1, 0, 5])

Cs.perform()

Cs.stop()

Import ctcsound

Cs = ctcsound.Csound()

Cs.compileOrc(orchestra)

Cs.setOption(”-odac”)

Cs.start()

Cs.perform()

Cs.scoreEvent(”i”, [1, 0, 5])

Cs.stop()

Any help would be much appreciated.

Kind regards,

Susanne

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Hi Susanne,

this is the description for this method from the ctcsound.py file:

def scoreEvent(self, absp2mode, opcod, pFields):
        """Sends a score event.
        
        The event has type *opcod* (e.g. 'i' for a note event).
        *pFields* is tuple, a list, or an ndarray of MYFLTs with all the pfields
        for this event, starting with the p1 value specified in *pFields[0]*.
        If *absp2mode* is non-zero, the start time of the event is measured
        from the beginning of performance, instead of the default of relative
        to the current time.
        """

So we would need for instance:

cs.scoreEvent(time, “i”, [1, 0, 5])

Hi Victor.
Thanks for the suggestion. However, when I try it, I get a syntax error saying that four arguments were given, when 3 positional arguments were expected.

Kind regards,
Susanne

Hi tarmo,

No, that didn’t make a difference. Thanks for the idea though.

Kind regards,

Susanne

Ok, maybe the version I have has actually changed. I tried

helpctcsound\.Csound\.scoreEvent

Help on function scoreEvent in module ctcsound:

scoreEventself, type\_, pFields
    Sends a new score event.
         > *type_* is the score event type &#39;a&#39;, &#39;i&#39;, &#39;q&#39;, &#39;f&#39;, or &#39;e&#39;.
    > *pFields* is a tuple, a list, or an ndarray of MYFLTs with all the
      pfields for this event, starting with the p1 value specified in
      pFields[0].

So you are right, it does not have the time argument. The version I was looking at is different.

I looked at your original code and the problem is that you are running Csound in the same
thread as you are trying to put events in. You need to run in a separate thread, see
the example

https://github.com/csound/csoundAPI_examples/blob/master/python/py3/example4.py

For instance,

import ctcsound
cs = ctcsound.Csound()
cs.setOption&#39;\-odac&#39;

0

cs.compileOrc('''

... instr 1
... out oscilip4,p5
... endin''')
0

cs.start()

rtaudio: PortAudio module enabled ...
using callback interface
rtmidi: PortMIDI module enabled
--Csound version 6.18 double samples Nov 24 2022

commit: a1580f9cdf331c35dceb486f4231871ce0b00266

libsndfile-1.1.0
graphics suppressed, ascii substituted
sr = 44100.0, kr = 4410.000, ksmps = 10
0dBFS level = 32768.0, A4 tuning = 440.0
orch now loaded
audio buffered in 1024 sample-frame blocks
PortAudio V19.7.0-devel, revision 147dd722548358763a8b649b3e4b41dfffbcfbb6
   0: dac0 BlackHole 2ch \[Core Audio, 2 in, 2 out\]
   1: dac1 MacBook Pro Speakers \[Core Audio, 0 in, 2 out\]
   2: dac2 Microsoft Teams Audio \[Core Audio, 2 in, 2 out\]
   3: dac3 ZoomAudioDevice \[Core Audio, 2 in, 2 out\]
   4: dac4 Multi\-Output Device \[Core Audio, 0 in, 2 out\]
   5: dac5 Aggregate Device \[Core Audio, 3 in, 4 out\]
PortAudio: selected output device 'MacBook Pro Speakers'
writing 1024 sample blks of 64-bit floats to dac
SECTION 1:
0

t = ctcsound.CsoundPerformanceThreadcs\.csound\()
t.play()
cs.scoreEvent&quot;i&quot;,\[1,0,1,4000,550\]

  rtevent: T 27.023 TT 27.023 M: 0.0
new alloc for instr 1:
0

and you’ll hear a beep.

Hi Victor.
Wow, that works! I've been trying to figure this out for about a week now, so right now, I'm ecstatic. Thank you so much!

Kind regards,
Susanne