Csound Csound-dev Csound-tekno Search About

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

Date2023-11-09 08:46
FromSusanne Pedersen
Subject[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

 


Date2023-11-09 10:27
FromTarmo Johannes
SubjectRe: [Csnd] How do I use the scoreEvent method in CTCsound
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

Date2023-11-09 11:16
FromVictor Lazzarini
SubjectRe: [Csnd] [EXTERNAL] [Csnd] How do I use the scoreEvent method in CTCsound
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])


========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 9 Nov 2023, at 08:46, Susanne Pedersen  wrote:
> 
> WARNING This email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
> 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 tohttps://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

Date2023-11-09 11:31
FromSusanne Pedersen
SubjectRe: [Csnd] [EXTERNAL] [Csnd] How do I use the scoreEvent method in CTCsound
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


-----Original Message-----
From: A discussion list for users of Csound  On Behalf Of Victor Lazzarini
Sent: 9. november 2023 12:17
To: CSOUND@LISTSERV.HEANET.IE
Subject: Re: [Csnd] [EXTERNAL] [Csnd] How do I use the scoreEvent method in CTCsound

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])


========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 9 Nov 2023, at 08:46, Susanne Pedersen  wrote:
> 
> WARNING This email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
> 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 
> tohttps://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

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

Date2023-11-09 11:33
FromSusanne Pedersen
SubjectRe: [Csnd] How do I use the scoreEvent method in CTCsound

Hi tarmo,

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

 

Kind regards,

Susanne

 

 

From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> On Behalf Of Tarmo Johannes
Sent: 9. november 2023 11:28
To: CSOUND@LISTSERV.HEANET.IE
Subject: Re: [Csnd] How do I use the scoreEvent method in CTCsound

 

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


Date2023-11-09 12:06
FromVictor Lazzarini
SubjectRe: [Csnd] [EXTERNAL] [Csnd] How do I use the scoreEvent method in CTCsound
Ok, maybe the version I have has actually changed. I tried

>>> help(ctcsound.Csound.scoreEvent)

Help on function scoreEvent in module ctcsound:

scoreEvent(self, type_, pFields)
    Sends a new score event.
         | *type_* is the score event type ('a', 'i', 'q', 'f', or 'e').
    | *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('-odac')
0
>>> cs.compileOrc('''
... instr 1
... out oscili(p4,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.CsoundPerformanceThread(cs.csound())
>>> t.play()
>>> cs.scoreEvent("i",[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).
========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 9 Nov 2023, at 11:31, Susanne Pedersen  wrote:
>
> 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
>
>
> -----Original Message-----
> From: A discussion list for users of Csound  On Behalf Of Victor Lazzarini
> Sent: 9. november 2023 12:17
> To: CSOUND@LISTSERV.HEANET.IE
> Subject: Re: [Csnd] [EXTERNAL] [Csnd] How do I use the scoreEvent method in CTCsound
>
> 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])
>
>
> ========================
> Prof. Victor Lazzarini
> Maynooth University
> Ireland
>
>> On 9 Nov 2023, at 08:46, Susanne Pedersen  wrote:
>>
>> WARNING This email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
>> 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
>> tohttps://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
>
> 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

Date2023-11-09 13:39
FromSusanne Pedersen
SubjectRe: [Csnd] [EXTERNAL] [Csnd] How do I use the scoreEvent method in CTCsound
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


-----Original Message-----
From: A discussion list for users of Csound  On Behalf Of Victor Lazzarini
Sent: 9. november 2023 13:07
To: CSOUND@LISTSERV.HEANET.IE
Subject: Re: [Csnd] [EXTERNAL] [Csnd] How do I use the scoreEvent method in CTCsound

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

>>> help(ctcsound.Csound.scoreEvent)

Help on function scoreEvent in module ctcsound:

scoreEvent(self, type_, pFields)
    Sends a new score event.
         | *type_* is the score event type ('a', 'i', 'q', 'f', or 'e').
    | *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('-odac')
0
>>> cs.compileOrc('''
... instr 1
... out oscili(p4,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.CsoundPerformanceThread(cs.csound())
>>> t.play()
>>> cs.scoreEvent("i",[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).
========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 9 Nov 2023, at 11:31, Susanne Pedersen  wrote:
>
> 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
>
>
> -----Original Message-----
> From: A discussion list for users of Csound 
>  On Behalf Of Victor Lazzarini
> Sent: 9. november 2023 12:17
> To: CSOUND@LISTSERV.HEANET.IE
> Subject: Re: [Csnd] [EXTERNAL] [Csnd] How do I use the scoreEvent 
> method in CTCsound
>
> 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])
>
>
> ========================
> Prof. Victor Lazzarini
> Maynooth University
> Ireland
>
>> On 9 Nov 2023, at 08:46, Susanne Pedersen  wrote:
>>
>> WARNING This email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
>> 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 
>> tohttps://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
>
> 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

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