Csound Csound-dev Csound-tekno Search About

[Csnd] macros for csoundapi~?

Date2008-02-23 09:53
From"Chuckk Hubbard"
Subject[Csnd] macros for csoundapi~?
AttachmentsNone  

Date2008-02-23 09:59
From"Chuckk Hubbard"
Subject[Csnd] Re: macros for csoundapi~?
AttachmentsNone  

Date2008-02-23 11:55
FromIain McCurdy
Subject[Csnd] RE: macros for csoundapi~?
Hi Chuckk,
You can trigger lists of score events at any time using timedseq. Scores can be stored either in function tables or in separate text files which are loaded into GEN 23 tables. Scores can also be looped. Let me know if you'd like an example.
Bye,
Iain

> Date: Sat, 23 Feb 2008 11:53:21 +0200
> From: badmuthahubbard@gmail.com
> To: csound@lists.bath.ac.uk
> Subject: [Csnd] macros for csoundapi~?
>
> Hi.
> I'm using csoundapi~ to send score events from Pd, and I'd like to
> make a percussion track in .sco format to accompany, rather than
> adding drum sequencing to my Pd patch. I have my sequencer now
> sending tempo control events, and sending p3 in beats instead of
> seconds, and now I'm wondering how I can make a section of .sco that
> will only play when the Pd sequencer starts, instead of when the .sco
> loads. I initially thought to put the percussion .sco events right in
> the .csd, and send something like "run 0" to csoundapi~ when it loads;
> but now I'm wondering if it would be possible to put score macros in
> the .csd file and trigger them through csoundapi~. Something like
> "event $PATTERN01"...
> Any possibilities for something like this?
>
> Maybe I could write all the percussion .sco events as event_i commands
> in a separate instrument that could be called whenever the Pd
> sequencer starts?
> Let me know if I'm not explaining this well enough.
> Thanks.
>
> -Chuckk
>
> --
> http://www.badmuthahubbard.com
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"


Climb to the top of the charts! Play the word scramble challenge with star power. Play now!

Date2008-02-24 14:57
From"Chuckk Hubbard"
Subject[Csnd] Re: RE: macros for csoundapi~?
AttachmentsNone  undefined.csd  

Date2008-02-25 20:10
FromAnthony Kozar
Subject[Csnd] Re: Re: RE: macros for csoundapi~?
First, your example fails because it appears that #define must come at the
beginning of a line.  Once that is fixed, it fails because you are expanding
a multi-line macro inside of string quotes:

    scoreline "$PAT01(ktime)", kpat01

becomes

    scoreline "
i2    [ktime+0]    .25
i2    [ktime+.5]    .25
i2    [ktime+1]    .25
i2    [ktime+1.5] .25
", kpat01

Note that orchestra macros are expanded while the orchestra is read in
(before it is "compiled") and score macros are expanded before the score is
sorted.  Macros are never expanded at performance time.

You can create multi-line strings by enclosing them in {{ }}, so I tried

    scoreline {{$PAT01(ktime)}}, kpat01

but that results in a lot of the following error message:

unknown opcode $
illegal RT scoreline:
$PAT01(ktime)
^

So, it appears that macros are not expanded inside of multi-line strings.
(Is this a bug??)

Even if we could get the macro to expand properly here, there are still a
number of reasons that it will not work as you would like it to.  As you can
see from the above expansion, the $TIME parameter is replaced with the text
"ktime", not the value of ktime.  And the real-time score event interpreter
doesn't understand "ktime".

For illustrative purposes, I tried the following

#define PAT02(TIME) #i2    [$TIME.+0]    .25#

    scoreline "$PAT02(ktime)", kpat01

and I get the following error

illegal RT scoreline:
i2  [ktime+0]   .25
   ^

This illustrates the other main problem: real-time score events do not go
through the score pre-processor and sorter.  Score features such as
expressions ([ktime+0]), carry symbols, loops, tempo warping, etc. are all
part of a pre-performance pre-processing phase.  Real-time events can only
have literal numeric or string parameters.

However, I think the start times of real-time events are always relative to
the current performance time, so the following may work just fine for you:

    scoreline {{
        i2    0    .25
        i2    .5   .25
        i2    1    .25
        i2    1.5  .25
    }}, kpat01

(I cannot test it, because scoreline does not seem to work on MacOS 9).  If
it does not, then your idea of using separate "event" opcodes should work.

Good luck,

Anthony Kozar
mailing-lists-1001 AT anthonykozar DOT net
http://anthonykozar.net/

Chuckk Hubbard wrote on 2/24/08 9:57 AM:

> I have been looking at scoreline, to try to use it to trigger a score
> macro, but it don't work.  It attempts to replace $MACRO with an
> orchestra macro, rather than sending it as a scoreline event.  So now
> I'm trying the macro in the orchestra, but with no luck: somehow I get
> an error message that the macro TIME is undefined with the attached
> .csd file.  Anyone see why?

>>> Maybe I could write all the percussion .sco events as event_i commands
>>> in a separate instrument that could be called whenever the Pd
>>> sequencer starts?


Date2008-02-25 23:17
From"Chuckk Hubbard"
Subject[Csnd] Re: Re: Re: RE: macros for csoundapi~?
AttachmentsNone  

Date2008-02-25 23:22
From"Chuckk Hubbard"
Subject[Csnd] Re: RE: macros for csoundapi~?
AttachmentsNone  

Date2008-02-26 00:51
FromIain McCurdy
Subject[Csnd] RE: Re: RE: macros for csoundapi~?
Here you go. Save the following as two files: first the .csd and then a text file "scale.txt". It just plays a major scale at different tempi. Note durations are interpretted as beats which I think is one of the things you mentioned.


--------timedseq.csd---------------------------------------------------------------------------------------------------------------------------------------------------
<CsoundSynthesizer>

<CsOptions>
-odevaudio
</CsOptions>

<CsInstruments>

sr     =     44100 
ksmps     =     10
nchnls     =     2
   
gisine        ftgen        0,0,4096,10,1    ;A SINE WAVE
giscale        ftgen         0,0,128,-23,"scale.txt"    ;PHRASE FROM EXTERNAL TEXT FILE

instr    1    ;NOTE TRIGGERING INSTRUMENT
itempo    =    p4    ;TEMPO VALUE FROM p4
kBPS    =    itempo/60    ;DERIVE BEATS-PER-SECOND
ibeats    =    4    ;NUMBER OF BEATS IN LOOP
kphase    phasor  kBPS/ibeats    ;DEFINE PHASOR ACCORDING TO BEATS-PER-SECOND AND NUMBER OF BEAT IN PHRASE
kpointer    =        kphase * ibeats    ;MULTIPLY PHASE VALUE BY NUMBER OF BEATS
kp1        init    0    ;INITIALISE P-FIELD VARIABLES
kp2        init    0       ;INITIALISE P-FIELD VARIABLES
kp3        init    0       ;INITIALISE P-FIELD VARIABLES
kp4        init    0       ;INITIALISE P-FIELD VARIABLES
ktrigger   timedseq kpointer, giscale, kp1, kp2,kp3, kp4    ;READ CURRENT TRIGGER AND P-FIELDS FROM FUNCTION TABLE
schedkwhen ktrigger, 0, 0, 2, 0, kp3/kBPS, kp4    ;p3 VALUES ARE SCALED ACCORDING TO TEMPO (ALTHOUGH THEY COULD BE LEFT UNSCALED
endin

instr    2    ;SOUND GENERATING INSTRUMENT
aenv    line    1,(p3),0    ;AMPLITUDE ENVELOPE
asig    oscili    5000*aenv, cpspch(p4), gisine    ;OSCILLATOR
outs    asig, asig    ;SEND AUDIO TO OUTPUTS
endin
             
</CsInstruments>

<CsScore>
i 1 0 4 60    ;PLAY PHRASE ONCE AT 60BPM
i 1 5 2 120    ;PLAY PHRASE ONCE AT 120BPM
i 1 8 4 240    ;PLAY PHRASE FOUR TIMES AT 240BPM
e
</CsScore>

</CsoundSynthesizer>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

---------scale.txt-----------
instr   strt    dur     pch
2         0      0.5    8.00
2      0.5      0.5    8.02
2         1      0.5    8.04
2      1.5      0.5    8.05
2         2      0.5    8.07
2      2.5      0.5    8.09
2         3      0.5    8.11
2      3.5      0.5    9.00
2         4      0.5    8.00
-1        4       -1      -1
-------------------------------

Bye,
Iain

> Date: Tue, 26 Feb 2008 01:22:15 +0200
> From: badmuthahubbard@gmail.com
> To: csound@lists.bath.ac.uk
> Subject: [Csnd] Re: RE: macros for csoundapi~?
>
> Hi again Iain.
> Finally, yes, I'd appreciate any working examples you could share.
> This attached file isn't one!
> It tells me that shedkwhen is trying to use 0 as instr number.
> Doesn't seem like that should be possible, if both the trigger and the
> instr number are directly from the output of timedseq...
>
> Thanks, I think you were right from the beginning.
> -Chuckk
>
> On Sat, Feb 23, 2008 at 1:55 PM, Iain McCurdy <i_mccurdy@hotmail.com> wrote:
> >
> > Hi Chuckk,
> > You can trigger lists of score events at any time using timedseq. Scores can
> > be stored either in function tables or in separate text files which are
> > loaded into GEN 23 tables. Scores can also be looped. Let me know if you'd
> > like an example.
> > Bye,
> > Iain
> >
> > > Date: Sat, 23 Feb 2008 11:53:21 +0200
> > > From: badmuthahubbard@gmail.com
> > > To: csound@lists.bath.ac.uk
> > > Subject: [Csnd] macros for csoundapi~?
> >
> >
> > >
> > > Hi.
> > > I'm using csoundapi~ to send score events from Pd, and I'd like to
> > > make a percussion track in .sco format to accompany, rather than
> > > adding drum sequencing to my Pd patch. I have my sequencer now
> > > sending tempo control events, and sending p3 in beats instead of
> > > seconds, and now I'm wondering how I can make a section of .sco that
> > > will only play when the Pd sequencer starts, instead of when the .sco
> > > loads. I initially thought to put the percussion .sco events right in
> > > the .csd, and send something like "run 0" to csoundapi~ when it loads;
> > > but now I'm wondering if it would be possible to put score macros in
> > > the .csd file and trigger them through csoundapi~. Something like
> > > "event $PATTERN01"...
> > > Any possibilities for something like this?
> > >
> > > Maybe I could write all the percussion .sco events as event_i commands
> > > in a separate instrument that could be called whenever the Pd
> > > sequencer starts?
> > > Let me know if I'm not explaining this well enough.
> > > Thanks.
> > >
> > > -Chuckk
> > >
> > > --
> > > http://www.badmuthahubbard.com
> > >
> > >
> > > Send bugs reports to this list.
> > > To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> > csound"
> >
> > ________________________________
> > Climb to the top of the charts! Play the word scramble challenge with star
> > power. Play now!
>
>
>
> --
> http://www.badmuthahubbard.com
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"


Shed those extra pounds with MSN and The Biggest Loser! Learn more.

Date2008-02-26 02:51
From"Dr. Richard Boulanger"
Subject[Csnd] Re: RE: Re: RE: macros for csoundapi~?
Nice Ian!  Thanks for sharing.

-dB

On Feb 25, 2008, at 7:51 PM, Iain McCurdy wrote:

Here you go. Save the following as two files: first the .csd and then a text file "scale.txt". It just plays a major scale at different tempi. Note durations are interpretted as beats which I think is one of the things you mentioned.


--------timedseq.csd---------------------------------------------------------------------------------------------------------------------------------------------------
<CsoundSynthesizer>

<CsOptions>
-odevaudio
</CsOptions>

<CsInstruments>

sr     =     44100  
ksmps     =     10
nchnls     =     2
    
gisine        ftgen        0,0,4096,10,1    ;A SINE WAVE
giscale        ftgen         0,0,128,-23,"scale.txt"    ;PHRASE FROM EXTERNAL TEXT FILE

instr    1    ;NOTE TRIGGERING INSTRUMENT
itempo    =    p4    ;TEMPO VALUE FROM p4
kBPS    =    itempo/60    ;DERIVE BEATS-PER-SECOND 
ibeats    =    4    ;NUMBER OF BEATS IN LOOP
kphase    phasor  kBPS/ibeats    ;DEFINE PHASOR ACCORDING TO BEATS-PER-SECOND AND NUMBER OF BEAT IN PHRASE
kpointer    =        kphase * ibeats    ;MULTIPLY PHASE VALUE BY NUMBER OF BEATS
kp1        init    0    ;INITIALISE P-FIELD VARIABLES
kp2        init    0       ;INITIALISE P-FIELD VARIABLES
kp3        init    0       ;INITIALISE P-FIELD VARIABLES
kp4        init    0       ;INITIALISE P-FIELD VARIABLES
ktrigger   timedseq kpointer, giscale, kp1, kp2,kp3, kp4    ;READ CURRENT TRIGGER AND P-FIELDS FROM FUNCTION TABLE
schedkwhen ktrigger, 0, 0, 2, 0, kp3/kBPS, kp4    ;p3 VALUES ARE SCALED ACCORDING TO TEMPO (ALTHOUGH THEY COULD BE LEFT UNSCALED
endin

instr    2    ;SOUND GENERATING INSTRUMENT
aenv    line    1,(p3),0    ;AMPLITUDE ENVELOPE
asig    oscili    5000*aenv, cpspch(p4), gisine    ;OSCILLATOR
outs    asig, asig    ;SEND AUDIO TO OUTPUTS
endin
              
</CsInstruments>

<CsScore>
i 1 0 4 60    ;PLAY PHRASE ONCE AT 60BPM
i 1 5 2 120    ;PLAY PHRASE ONCE AT 120BPM
i 1 8 4 240    ;PLAY PHRASE FOUR TIMES AT 240BPM
e
</CsScore>

</CsoundSynthesizer>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

---------scale.txt-----------
instr   strt    dur     pch
2         0      0.5    8.00
2      0.5      0.5    8.02
2         1      0.5    8.04
2      1.5      0.5    8.05
2         2      0.5    8.07
2      2.5      0.5    8.09
2         3      0.5    8.11
2      3.5      0.5    9.00
2         4      0.5    8.00
-1        4       -1      -1
-------------------------------

Bye,
Iain

> Date: Tue, 26 Feb 2008 01:22:15 +0200
> From: badmuthahubbard@gmail.com
> To: csound@lists.bath.ac.uk
> Subject: [Csnd] Re: RE: macros for csoundapi~?
> 
> Hi again Iain.
> Finally, yes, I'd appreciate any working examples you could share.
> This attached file isn't one!
> It tells me that shedkwhen is trying to use 0 as instr number.
> Doesn't seem like that should be possible, if both the trigger and the
> instr number are directly from the output of timedseq...
> 
> Thanks, I think you were right from the beginning.
> -Chuckk
> 
> On Sat, Feb 23, 2008 at 1:55 PM, Iain McCurdy <i_mccurdy@hotmail.com> wrote:
> >
> > Hi Chuckk,
> > You can trigger lists of score events at any time using timedseq. Scores can
> > be stored either in function tables or in separate text files which are
> > loaded into GEN 23 tables. Scores can also be looped. Let me know if you'd
> > like an example.
> > Bye,
> > Iain
> >
> > > Date: Sat, 23 Feb 2008 11:53:21 +0200
> > > From: badmuthahubbard@gmail.com
> > > To: csound@lists.bath.ac.uk
> > > Subject: [Csnd] macros for csoundapi~?
> >
> >
> > >
> > > Hi.
> > > I'm using csoundapi~ to send score events from Pd, and I'd like to
> > > make a percussion track in .sco format to accompany, rather than
> > > adding drum sequencing to my Pd patch. I have my sequencer now
> > > sending tempo control events, and sending p3 in beats instead of
> > > seconds, and now I'm wondering how I can make a section of .sco that
> > > will only play when the Pd sequencer starts, instead of when the .sco
> > > loads. I initially thought to put the percussion .sco events right in
> > > the .csd, and send something like "run 0" to csoundapi~ when it loads;
> > > but now I'm wondering if it would be possible to put score macros in
> > > the .csd file and trigger them through csoundapi~. Something like
> > > "event $PATTERN01"...
> > > Any possibilities for something like this?
> > >
> > > Maybe I could write all the percussion .sco events as event_i commands
> > > in a separate instrument that could be called whenever the Pd
> > > sequencer starts?
> > > Let me know if I'm not explaining this well enough.
> > > Thanks.
> > >
> > > -Chuckk
> > >
> > > --
> > > http://www.badmuthahubbard.com
> > >
> > >
> > > Send bugs reports to this list.
> > > To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> > csound"
> >
> > ________________________________
> > Climb to the top of the charts! Play the word scramble challenge with star
> > power. Play now!
> 
> 
> 
> -- 
> http://www.badmuthahubbard.com
> 
> 
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"


Shed those extra pounds with MSN and The Biggest Loser! Learn more.


Date2008-02-26 18:16
From"Chuckk Hubbard"
Subject[Csnd] Re: RE: Re: RE: macros for csoundapi~?
AttachmentsNone  

Date2008-02-27 19:32
From"Chuckk Hubbard"
Subject[Csnd] Re: RE: Re: RE: macros for csoundapi~?
AttachmentsNone