[Csnd] Csound API - cancelling events
Date | 2020-04-28 07:52 |
From | sjakops |
Subject | [Csnd] Csound API - cancelling events |
I can't seem to find a 'proper' way to remove/cancel instrument events that have been sent via csoundInputMessage(). I want to be able to send a score like the following and then after 2 seconds turn off instrument 1 (using csoundInputMessage?). i 1 0 1 i 1 1 2 i 1 3 1 i 2 3 1 After sending this score I can send a note off event (to activate a nice release), but then the notes after that are still being played. Then I have tried using a counter, so that within the instrument it can be determined if the note should be played or not, but this is somehow unstable (the counter doesn't always seem to be immediately updated when I use csoundInputMessage to activate the instrument that updates the counter). -- Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html 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 |
Date | 2020-04-28 09:02 |
From | Rory Walsh |
Subject | Re: [Csnd] Csound API - cancelling events |
How about not using a score, but triggering the events with an instrument instead? That way you can simply disable the instrument that is spawning the events? On Tue, 28 Apr 2020 at 07:53, sjakops <sorenkj@gmail.com> wrote: I can't seem to find a 'proper' way to remove/cancel instrument events that |
Date | 2020-04-28 11:09 |
From | Søren Jakobsen |
Subject | Re: [Csnd] Csound API - cancelling events |
Hi Rory, thanks, I have tried that, but abandoned the idea as I am using sort of a complex process to generate the score - it is simply too difficult to implement that in Csound. So I'm really hoping there is a way to cancel these 'score fragments' that I'm sending. Søren On 4/28/20, Rory Walsh |
Date | 2020-04-28 11:47 |
From | Søren Jakobsen |
Subject | Re: [Csnd] Csound API - cancelling events |
Ah.. I could probably send those generated score fragments in a parameter to an instrument that plays the score via the scoreline opcode.. but then still, would the events be cancelled when I turn off that instrument? I guess I have to try it out.. On 4/28/20, Søren Jakobsen |
Date | 2020-04-28 12:03 |
From | Tarmo Johannes |
Subject | Re: [Csnd] Csound API - cancelling events |
Hi, Maybe you can write a stopper instrument based on turnoff2 and that take the instrument to stop as a parameter and call that wheneve you need to stop something? Or same way you can write a StopAll instrument as you need. instr Stopper iNumber = p4 turnoff2 iNumber, 0, 1 endin tarmo Kontakt Søren Jakobsen (<sorenkj@gmail.com>) kirjutas kuupäeval T, 28. aprill 2020 kell 13:47: Ah.. I could probably send those generated score fragments in a |
Date | 2020-04-28 12:06 |
From | Søren Jakobsen |
Subject | Re: [Csnd] Csound API - cancelling events |
hi Tarmo, thanks - that sound like a good idea too. I just wonder if turnoff2 is equal to a note off event (an i statement with negative instrument number) - then it will not work, but I'll try it out! On 4/28/20, Tarmo Johannes |
Date | 2020-04-28 12:08 |
From | Tarmo Johannes |
Subject | Re: [Csnd] Csound API - cancelling events |
Yes, the great thing with turnoff2 is that you can stop both notes with definite and indefinite duration. Don't forget to use envelopes with release segments like madsr or linenr for envelopes! tarmo Kontakt Søren Jakobsen (<sorenkj@gmail.com>) kirjutas kuupäeval T, 28. aprill 2020 kell 14:06: hi Tarmo, thanks - that sound like a good idea too. I just wonder if |
Date | 2020-04-28 12:41 |
From | Søren Jakobsen |
Subject | Re: [Csnd] Csound API - cancelling events |
Unfortunately calling turnoff2 after 2 seconds does not prevent the third note (timed at 3) to play. However, strangely, if I run the 'stopper instrument' with an infinite duration and use "turnoff2 p4, 12, 1" (p4 is the instrument number/fraction) the third note is started, and then immediately stopped. On 4/28/20, Tarmo Johannes |
Date | 2020-04-28 13:06 |
From | Tarmo Johannes |
Subject | Re: [Csnd] Csound API - cancelling events |
Hi, When stopper instrument runs forever, it executes the turnuoff on every k-cycle so as soon the instrument is started it is stopped. But since it was initiated, it gets to play its release phase. And naturally you cannot turnoff instruments that will run in future this way, you probably need some kind of flag in the instrument or your code that start them. I may start finally understanding what you need - is it so that you send instrument calls (inputEvent) from API that will run in future and you may want to may want to say later, "Don't start!"? Maybe you can use a kind of flag in a channel or global variable that you can control via API like: chnset 1, "mayStart" ; set it to 0 to stop playback instr 1 if (chnget:i("mayStart")==0) then turnoff endif ..... endin I am not sure if this way the release phase is started or not. you may need to set the amp of the instrument to 0 from the if block then. Hope it helps tarmo Kontakt Søren Jakobsen (<sorenkj@gmail.com>) kirjutas kuupäeval T, 28. aprill 2020 kell 14:41: Unfortunately calling turnoff2 after 2 seconds does not prevent the |
Date | 2020-04-28 14:17 |
From | Michael Gogins |
Subject | Re: [Csnd] Csound API - cancelling events |
Either the 'd' score opcode, or a negative instrument number of name, will turn off a note. However, the note in question must be an "always on" note, that is, it must have a negative p3. I use this in some of my pieces. Sample: <CsoundSynthesizer> <CsOptions> -d -m195 -odac:plughw:1,0 </CsOptions> <CsInstruments> sr = 48000 ksmps = 128 nchnls = 2 nchnls_i = 1 instr 1 a1 oscil 10000, 440 out a1 endin instr sound a1 oscil 10000, 440 out a1 endin </CsInstruments> <CsScore> f 0 10 ; p3 must be negative or the note cannot be turned off. i 1 0 -10 d 1 1 0 ; p3 must be negative or the note cannot be turned off. i "sound" 3 -10 i "-sound" 4 0 ; d and -p1 seem to behave identically. </CsScore> </CsoundSynthesizer> Regards, Mike ----------------------------------------------------- Michael GoginsIrreducible Productions http://michaelgogins.tumblr.com Michael dot Gogins at gmail dot com On Tue, Apr 28, 2020 at 8:06 AM Tarmo Johannes <trmjhnns@gmail.com> wrote:
|
Date | 2020-04-28 15:02 |
From | thorin kerr |
Subject | Re: [Csnd] Csound API - cancelling events |
Attachments | earlyoff.csd |
Here's an example which turns off, observes envelopes and turns off the next notes. You'd have to get more elaborate with the globals and conditionals to generalise this with multiple instruments. Thorin On Tue, Apr 28, 2020 at 4:52 PM sjakops <sorenkj@gmail.com> wrote: I can't seem to find a 'proper' way to remove/cancel instrument events that |
Date | 2020-04-28 15:51 |
From | Michael Gogins |
Subject | Re: [Csnd] Csound API - cancelling events |
I should add, that I use the 'd' opcode to turn off notes; both note on and not off are sent with csoundInputMessage. ----------------------------------------------------- Michael GoginsIrreducible Productions http://michaelgogins.tumblr.com Michael dot Gogins at gmail dot com On Tue, Apr 28, 2020 at 9:17 AM Michael Gogins <michael.gogins@gmail.com> wrote:
|
Date | 2020-04-28 16:49 |
From | Søren Jakobsen |
Subject | Re: [Csnd] Csound API - cancelling events |
Thanks all for the tips, but the solution with a flag inside the instrument (and the note off/d statement) is what I have already tried, and it is somehow not 'stable'. It works perfectly for some seconds after the performance starts, but then it starts behaving unpredictably. I have been wondering if the delay opcodes (inside an 'always on' instrument) interfere with the execution of instruments, because if I disable the delay it stays stable. I have tested if using a really big buffer helps (that the instrumente events are not falling out because of performance problems), but it doesn't help either. On 4/28/20, Michael Gogins |
Date | 2020-04-28 16:55 |
From | Rory Walsh |
Subject | Re: [Csnd] Csound API - cancelling events |
There is a csoundSetScorePending method in the API. I wonder if this is of any use? On Tue, 28 Apr 2020 at 16:49, Søren Jakobsen <sorenkj@gmail.com> wrote: Thanks all for the tips, but the solution with a flag inside the |
Date | 2020-04-28 17:06 |
From | Søren Jakobsen |
Subject | Re: [Csnd] Csound API - cancelling events |
I don't think csoundSetScorePending can be used here, because all the events are real-time, and it is not all the playing events I want to turn off. On 4/28/20, Rory Walsh |
Date | 2020-04-28 18:51 |
From | Rory Walsh |
Subject | Re: [Csnd] Csound API - cancelling events |
Of course. You're right. On Tue 28 Apr 2020, 17:06 Søren Jakobsen, <sorenkj@gmail.com> wrote: I don't think csoundSetScorePending can be used here, because all the |
Date | 2020-04-29 09:53 |
From | Rory Walsh |
Subject | Re: [Csnd] Csound API - cancelling events |
How about using a channel to disable instruments? Let's say you fire off these events. i 1 0 1 i 1 1 2 i 1 3 1 i 2 3 1 At any time, before these all get performed, you can call csoundSetChannel("disable", 1) or whatever. Your instruments should include a simple check: instr 1 if chnget:i("disable") == 1 && timeinstrk() > 0 then turnoff endif .... This will stop any instrument that has just been called to start, but will not stop any instrument that is already playing. You can always just use chnget:k() if you want this to also work at k-time. On Tue, 28 Apr 2020 at 18:51, Rory Walsh <rorywalsh@ear.ie> wrote:
|
Date | 2020-04-29 14:57 |
From | Søren Jakobsen |
Subject | Re: [Csnd] Csound API - cancelling events |
Attachments | test.zip |
Ok, it seems some kind of flag inside the instrument is the way to go. However, I am experiencing some 'instability' with this solution. I have attached a small example that should demonstrate the problem. On Windows please open the the .pb (PureBasic) file and run it (f5) - press the space bar repeatedly/quickly/randomly and within one minute or so it all 'breaks'. On 4/29/20, Rory Walsh |
Date | 2020-05-03 13:51 |
From | Søren Jakobsen |
Subject | Re: [Csnd] Csound API - cancelling events |
Can someone help me with this? I'm sorry I can't isolate the problem more.. I have just tested if this could be caused by the use of arrays (I know there have recently been some issues), but it doesn't seem so. I have also tried running with a huge buffer, but still experiencing the problem - so that should rule out that it is just a performance problem? So what is going on - am I using the delay opcodes in a wrong way? On 4/29/20, Søren Jakobsen |
Date | 2020-05-03 15:38 |
From | joachim heintz |
Subject | Re: [Csnd] Csound API - cancelling events |
if it is not windows specific, i can have a look. i understood it is windows only. On 03/05/2020 14:51, Søren Jakobsen wrote: > Can someone help me with this? I'm sorry I can't isolate the problem > more.. I have just tested if this could be caused by the use of arrays > (I know there have recently been some issues), but it doesn't seem so. > I have also tried running with a huge buffer, but still experiencing > the problem - so that should rule out that it is just a performance > problem? So what is going on - am I using the delay opcodes in a wrong > way? > > On 4/29/20, Søren Jakobsen |
Date | 2020-05-03 16:34 |
From | John ff |
Subject | Re: [Csnd] Csound API - cancelling events |
+1
On 3 May 2020, at 15:39, joachim heintz <jh@joachimheintz.de> wrote: if it is not windows specific, i can have a look. i understood it is |
Date | 2020-05-03 16:52 |
From | Søren Jakobsen |
Subject | Re: [Csnd] Csound API - cancelling events |
Great, thanks! I don't know if it's only on Windows, but PureBasic is actually cross-platform - if you just modify the line that loads the dll (dylib should be loaded instead?) you should be able to run the demo also on OSX and Linux. On 5/3/20, John ff |
Date | 2020-05-03 17:13 |
From | joachim heintz |
Subject | Re: [Csnd] Csound API - cancelling events |
i understood you followed rory's suggestion, to implement something like instr 1 if chnget:i("disable") == 1 && timeinstrk() > 0 then turnoff endif but i don't see anything like this in your orc code. are you trying to solve it via the api itself? On 03/05/2020 17:52, Søren Jakobsen wrote: > Great, thanks! I don't know if it's only on Windows, but PureBasic is > actually cross-platform - if you just modify the line that loads the > dll (dylib should be loaded instead?) you should be able to run the > demo also on OSX and Linux. > > On 5/3/20, John ff |
Date | 2020-05-03 17:53 |
From | Søren Jakobsen |
Subject | Re: [Csnd] Csound API - cancelling events |
I have followed the general suggestion og using a type of flag inside the instrument, to determine when to not activate the instrument - have tried several variations thereof, but actually not tried with chnget.. nevertheless, the code I posted should demonstrate a problem - do you also experience that the instrument stops reponding 'correctly' when the space bar is pressed? On 5/3/20, joachim heintz |
Date | 2020-05-03 17:55 |
From | Søren Jakobsen |
Subject | Re: [Csnd] Csound API - cancelling events |
N.b. the 'flag' is the variable 'gicurplay' - it can be updated by sending an instrument statement (instr 1) message via the API. Inside the instrument the activation of the note is bypassed by the statement: cggoto p4 != gicurplay, finish On 5/3/20, Søren Jakobsen |
Date | 2020-05-03 18:17 |
From | joachim heintz |
Subject | Re: [Csnd] Csound API - cancelling events |
no idea how to run this ... On 03/05/2020 18:53, Søren Jakobsen wrote: > I have followed the general suggestion og using a type of flag inside > the instrument, to determine when to not activate the instrument - > have tried several variations thereof, but actually not tried with > chnget.. nevertheless, the code I posted should demonstrate a problem > - do you also experience that the instrument stops reponding > 'correctly' when the space bar is pressed? > > On 5/3/20, joachim heintz |
Date | 2020-05-03 18:48 |
From | Søren Jakobsen |
Subject | Re: [Csnd] Csound API - cancelling events |
Sorry, you need this IDE: https://www.purebasic.com/download.php - then just open the .pb file and press 'f5' (keeping all the files in the same folder) I suppose it could also be a problem related to PureBasic.. I'm not so familiar with C, but I guess I could try to implement the same code in C. On 5/3/20, joachim heintz |
Date | 2020-08-21 10:43 |
From | Søren Jakobsen |
Subject | Re: [Csnd] Csound API - cancelling events |
Thought I should just mention that I have been able to recreate my demo with .NET/C# - in this version the problem does not appear, so it seems the problem was in fact with Purebasic, not Csound..:) Søren On 5/3/20, Søren Jakobsen |