Csound Csound-dev Csound-tekno Search About

[Csnd] patterns CS3 -> Csound alternative

Date2012-07-07 01:52
Frompeiman khosravi
Subject[Csnd] patterns CS3 -> Csound alternative
Hello,

Is there an easy Csound-based alternative to the SC3 patterns library?

Best,
Peiman

Date2012-07-07 01:53
Frompeiman khosravi
Subject[Csnd] Re: patterns CS3 -> Csound alternative
http://danielnouri.org/docs/SuperColliderHelp/Streams-Patterns-Events/Pattern.html

On 7 July 2012 01:52, peiman khosravi  wrote:
> Hello,
>
> Is there an easy Csound-based alternative to the SC3 patterns library?
>
> Best,
> Peiman

Date2012-07-07 22:34
FromTito Latini
SubjectRe: [Csnd] Re: patterns CS3 -> Csound alternative
AttachmentsNone  

Date2012-07-08 00:25
FromJustin Smith
SubjectRe: [Csnd] Re: patterns CS3 -> Csound alternative
In terms of actually *implementing* the patterns lib in csound, IIRC
all of the supercollider pattern generators can be derived in a
straightforward way from the lindenmayer generator (fixed sequences
and markov chains are just being simplified subsets of a lindenmayer
function generator for example). Of course implementing them in python
(or in my case I would probably pick clojure at this point) would be
much easier than doing the whole thing as csound opcodes.

On Sat, Jul 7, 2012 at 2:34 PM, Tito Latini  wrote:
>> Is there an easy Csound-based alternative to the SC3 patterns library?
>
> Some years ago I wrote a script to use Pbind with csound, pd etc.
> Here is a simple test `pbind_test.sc'
>
> // events: 16
> // template: i     0.5
>
> var score, frequencies;
>
> frequencies = Pseq(({440+100.0.rand2} ! 200));
>
> score = Pbind(
>         \instr, 1,
>         \at, Pseries(0,0.1,200),
>         \dur, Prand(({1.0.rand}!200),inf),
>         \amp, Pseq([80,83,72,88],inf),
>         \freq, frequencies + Pseq([0,100,200,300],inf)
> );
>
> The comment `// events: ...' is optional but `// template: ...' is
> mandatory and it is the format of the line for the output values.
> The template is very simple: the keys of Pbind are between <...> and
> the rest of the line remains unchanged ("i" and 0.5 in the example).
>
> The `score' variable in sclang is mandatory and the Pbind to convert
> has to be
>
>   score = Pbind(...);
>
> The arguments of the script are:
>
>   Usage: scl_pbind2cols scfile [num-of-events]
>
> num-of-events overwrites the value in `// events: ...' if it exists.
>
> We can use `socat' (SOcket CAT) to run a simple sclang server
>
>   socat pty,link=/tmp/sclang.in,echo=0 exec:sclang
>
> and finally, in another terminal (or we can start the server like a daemon):
>
> scl_pbind2cols pbind_test.sc
> i1 0 0.29935657978058 80 418.92990112305 0.5
> i1 0.1 0.25428187847137 83 535.72236537933 0.5
> i1 0.2 0.82031977176666 72 656.52870178223 0.5
> i1 0.3 0.8511688709259 88 778.21835517883 0.5
> i1 0.4 0.34435153007507 80 482.8480386734 0.5
> i1 0.5 0.55086886882782 83 530.33241271973 0.5
> ...
>
> Another example, only four events filtered with the `column' utility:
>
> scl_pbind2cols pbind_test.sc 4 | column -t
> i1  0    0.70760095119476    80  418.57472896576  0.5
> i1  0.1  0.0092399120330811  83  546.263256073    0.5
> i1  0.2  0.83638513088226    72  617.68080234528  0.5
> i1  0.3  0.83638513088226    88  758.24090480804  0.5
>
> We can use it in real time with
>
>   csound -L /some/fifo ...
>
> and
>
>   scl_pbind2cols pbind_test.sc > /some/fifo
>
> Only three lines to write a wrapper for 
>
> #!/bin/bash
> exec > "$2"
> /usr/local/bin/scl_pbind2cols "$1"
>
> Ok, here is the script:
>
> #!/usr/bin/perl
>
> # scl_pbind2cols
> # reads a scfile and prints the values generated by a Pbind
> # Tito Latini
>
> use strict;
> use warnings;
>
> usage() if (@ARGV < 1);
> my ($infile, $events_) = @ARGV;
>
> die "$infile absent: $!" unless -e $infile;
>
> # sclang server started with:
> #   socat pty,link=/tmp/sclang.in,echo=0 exec:sclang
> my $scinput = "/tmp/sclang.in";
> check_sclang_server($scinput);
>
> my $events   = $events_ || 0;
> my $str      = "";
> my $str_args = "";
>
> my $scfifo   = "/tmp/sclang.out";
> unless (-p $scfifo) {
>     use POSIX qw(mkfifo);
>     unlink $scfifo if -e $scfifo;
>     mkfifo($scfifo, 0600) or die "mkfifo $scfifo failed: $!";
> }
>
> open(SCL,    ">", $scinput) or die "Could not open $scinput: $!";
> open(SCFILE, "<", $infile)  or die "Could not open $infile: $!";
>
> print SCL "var sclFIFO;\n";
> while() {
>     if ($events == 0 && $_ =~ m|//\s+events:\s+(\d+)|) {
>         $events = ${1};
>     } elsif ($_ =~ m|//\s+template:\s|) {
>         my @Ev = split(' ', $_, -1);
>         foreach my $i (@Ev[2 .. $#Ev]) {
>             if($i =~ "(.*)<(.*)>(.*)") {
>                 $str .= "${1}%${3} ";
>                 $str_args .= ",ev.at(\\${2})";
>             } else {
>                 $str .= "${i} ";
>             }
>         }
>         $str = "
> sclFIFO = File(\"$scfifo\",\"w\");
> score=score.asStream;
> $events.do({var ev = score.next(Event.new);
>   if(ev.notNil, {sclFIFO.write(format(\"${str}\\n\"${str_args}))})});
> close(sclFIFO)\f
> ";
>     } else {
>         print SCL;
>     }
> }
> print SCL $str;
>
> open(FIFO, "<", $scfifo) or die "Could not open $scfifo: $!";
> print while();
>
> sub check_sclang_server {
>     my ($scinput) = shift;
>     if (! -e $scinput) {
>         print STDERR <<"EOF";
> no sclang server; open a terminal and run
>
>   socat pty,link=$scinput,echo=0 exec:sclang
>
> EOF
>     exit(1);
>     }
> }
>
> sub usage {
>     print STDERR "Usage: $0 scfile [num-of-events]\n";
>     exit(1);
> }
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>

Date2012-07-08 10:12
Frompeiman khosravi
SubjectRe: [Csnd] Re: patterns CS3 -> Csound alternative
Thanks Tito,

This is really useful.

I tried running your script with your test example `pbind_test.sc'.
But nothing happens, the script doesn't return an error but no output
is printed.

Thanks
Peiman

On 7 July 2012 22:34, Tito Latini  wrote:
>> Is there an easy Csound-based alternative to the SC3 patterns library?
>
> Some years ago I wrote a script to use Pbind with csound, pd etc.
> Here is a simple test `pbind_test.sc'
>
> // events: 16
> // template: i     0.5
>
> var score, frequencies;
>
> frequencies = Pseq(({440+100.0.rand2} ! 200));
>
> score = Pbind(
>         \instr, 1,
>         \at, Pseries(0,0.1,200),
>         \dur, Prand(({1.0.rand}!200),inf),
>         \amp, Pseq([80,83,72,88],inf),
>         \freq, frequencies + Pseq([0,100,200,300],inf)
> );
>
> The comment `// events: ...' is optional but `// template: ...' is
> mandatory and it is the format of the line for the output values.
> The template is very simple: the keys of Pbind are between <...> and
> the rest of the line remains unchanged ("i" and 0.5 in the example).
>
> The `score' variable in sclang is mandatory and the Pbind to convert
> has to be
>
>   score = Pbind(...);
>
> The arguments of the script are:
>
>   Usage: scl_pbind2cols scfile [num-of-events]
>
> num-of-events overwrites the value in `// events: ...' if it exists.
>
> We can use `socat' (SOcket CAT) to run a simple sclang server
>
>   socat pty,link=/tmp/sclang.in,echo=0 exec:sclang
>
> and finally, in another terminal (or we can start the server like a daemon):
>
> scl_pbind2cols pbind_test.sc
> i1 0 0.29935657978058 80 418.92990112305 0.5
> i1 0.1 0.25428187847137 83 535.72236537933 0.5
> i1 0.2 0.82031977176666 72 656.52870178223 0.5
> i1 0.3 0.8511688709259 88 778.21835517883 0.5
> i1 0.4 0.34435153007507 80 482.8480386734 0.5
> i1 0.5 0.55086886882782 83 530.33241271973 0.5
> ...
>
> Another example, only four events filtered with the `column' utility:
>
> scl_pbind2cols pbind_test.sc 4 | column -t
> i1  0    0.70760095119476    80  418.57472896576  0.5
> i1  0.1  0.0092399120330811  83  546.263256073    0.5
> i1  0.2  0.83638513088226    72  617.68080234528  0.5
> i1  0.3  0.83638513088226    88  758.24090480804  0.5
>
> We can use it in real time with
>
>   csound -L /some/fifo ...
>
> and
>
>   scl_pbind2cols pbind_test.sc > /some/fifo
>
> Only three lines to write a wrapper for 
>
> #!/bin/bash
> exec > "$2"
> /usr/local/bin/scl_pbind2cols "$1"
>
> Ok, here is the script:
>
> #!/usr/bin/perl
>
> # scl_pbind2cols
> # reads a scfile and prints the values generated by a Pbind
> # Tito Latini
>
> use strict;
> use warnings;
>
> usage() if (@ARGV < 1);
> my ($infile, $events_) = @ARGV;
>
> die "$infile absent: $!" unless -e $infile;
>
> # sclang server started with:
> #   socat pty,link=/tmp/sclang.in,echo=0 exec:sclang
> my $scinput = "/tmp/sclang.in";
> check_sclang_server($scinput);
>
> my $events   = $events_ || 0;
> my $str      = "";
> my $str_args = "";
>
> my $scfifo   = "/tmp/sclang.out";
> unless (-p $scfifo) {
>     use POSIX qw(mkfifo);
>     unlink $scfifo if -e $scfifo;
>     mkfifo($scfifo, 0600) or die "mkfifo $scfifo failed: $!";
> }
>
> open(SCL,    ">", $scinput) or die "Could not open $scinput: $!";
> open(SCFILE, "<", $infile)  or die "Could not open $infile: $!";
>
> print SCL "var sclFIFO;\n";
> while() {
>     if ($events == 0 && $_ =~ m|//\s+events:\s+(\d+)|) {
>         $events = ${1};
>     } elsif ($_ =~ m|//\s+template:\s|) {
>         my @Ev = split(' ', $_, -1);
>         foreach my $i (@Ev[2 .. $#Ev]) {
>             if($i =~ "(.*)<(.*)>(.*)") {
>                 $str .= "${1}%${3} ";
>                 $str_args .= ",ev.at(\\${2})";
>             } else {
>                 $str .= "${i} ";
>             }
>         }
>         $str = "
> sclFIFO = File(\"$scfifo\",\"w\");
> score=score.asStream;
> $events.do({var ev = score.next(Event.new);
>   if(ev.notNil, {sclFIFO.write(format(\"${str}\\n\"${str_args}))})});
> close(sclFIFO)\f
> ";
>     } else {
>         print SCL;
>     }
> }
> print SCL $str;
>
> open(FIFO, "<", $scfifo) or die "Could not open $scfifo: $!";
> print while();
>
> sub check_sclang_server {
>     my ($scinput) = shift;
>     if (! -e $scinput) {
>         print STDERR <<"EOF";
> no sclang server; open a terminal and run
>
>   socat pty,link=$scinput,echo=0 exec:sclang
>
> EOF
>     exit(1);
>     }
> }
>
> sub usage {
>     print STDERR "Usage: $0 scfile [num-of-events]\n";
>     exit(1);
> }
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>

Date2012-07-08 10:29
Frompeiman khosravi
SubjectRe: [Csnd] Re: patterns CS3 -> Csound alternative
Thanks Justin,

It would very nice indeed to have it implemented directly in Csound.

Re Python or any other language: if I'm going to have to learn another
language I'd rather delve into SC instead. It's a question of history
and context, I know many composers that use SC but I know of a handful
that compose in python or any other scripting language. And surely,
the algorithmic side of SC is really what makes it, and the fact that
doing DSP is so well integrated within that context.

So far all my attempt to generate textural materials algorithmically
in Csound has left me wanting more and everywhere I look I'm directed
to SC. Which makes me think, it may be wise to use both, they're not
both good at everything - e.g. if it's a question DSP then Csound all
the way no doubt, but algorithmic stuff... Am I missing what's under
my nose?

Why not a Csoundapi supercollider ugen?

P

On 8 July 2012 00:25, Justin Smith  wrote:
> In terms of actually *implementing* the patterns lib in csound, IIRC
> all of the supercollider pattern generators can be derived in a
> straightforward way from the lindenmayer generator (fixed sequences
> and markov chains are just being simplified subsets of a lindenmayer
> function generator for example). Of course implementing them in python
> (or in my case I would probably pick clojure at this point) would be
> much easier than doing the whole thing as csound opcodes.
>
> On Sat, Jul 7, 2012 at 2:34 PM, Tito Latini  wrote:
>>> Is there an easy Csound-based alternative to the SC3 patterns library?
>>
>> Some years ago I wrote a script to use Pbind with csound, pd etc.
>> Here is a simple test `pbind_test.sc'
>>
>> // events: 16
>> // template: i     0.5
>>
>> var score, frequencies;
>>
>> frequencies = Pseq(({440+100.0.rand2} ! 200));
>>
>> score = Pbind(
>>         \instr, 1,
>>         \at, Pseries(0,0.1,200),
>>         \dur, Prand(({1.0.rand}!200),inf),
>>         \amp, Pseq([80,83,72,88],inf),
>>         \freq, frequencies + Pseq([0,100,200,300],inf)
>> );
>>
>> The comment `// events: ...' is optional but `// template: ...' is
>> mandatory and it is the format of the line for the output values.
>> The template is very simple: the keys of Pbind are between <...> and
>> the rest of the line remains unchanged ("i" and 0.5 in the example).
>>
>> The `score' variable in sclang is mandatory and the Pbind to convert
>> has to be
>>
>>   score = Pbind(...);
>>
>> The arguments of the script are:
>>
>>   Usage: scl_pbind2cols scfile [num-of-events]
>>
>> num-of-events overwrites the value in `// events: ...' if it exists.
>>
>> We can use `socat' (SOcket CAT) to run a simple sclang server
>>
>>   socat pty,link=/tmp/sclang.in,echo=0 exec:sclang
>>
>> and finally, in another terminal (or we can start the server like a daemon):
>>
>> scl_pbind2cols pbind_test.sc
>> i1 0 0.29935657978058 80 418.92990112305 0.5
>> i1 0.1 0.25428187847137 83 535.72236537933 0.5
>> i1 0.2 0.82031977176666 72 656.52870178223 0.5
>> i1 0.3 0.8511688709259 88 778.21835517883 0.5
>> i1 0.4 0.34435153007507 80 482.8480386734 0.5
>> i1 0.5 0.55086886882782 83 530.33241271973 0.5
>> ...
>>
>> Another example, only four events filtered with the `column' utility:
>>
>> scl_pbind2cols pbind_test.sc 4 | column -t
>> i1  0    0.70760095119476    80  418.57472896576  0.5
>> i1  0.1  0.0092399120330811  83  546.263256073    0.5
>> i1  0.2  0.83638513088226    72  617.68080234528  0.5
>> i1  0.3  0.83638513088226    88  758.24090480804  0.5
>>
>> We can use it in real time with
>>
>>   csound -L /some/fifo ...
>>
>> and
>>
>>   scl_pbind2cols pbind_test.sc > /some/fifo
>>
>> Only three lines to write a wrapper for 
>>
>> #!/bin/bash
>> exec > "$2"
>> /usr/local/bin/scl_pbind2cols "$1"
>>
>> Ok, here is the script:
>>
>> #!/usr/bin/perl
>>
>> # scl_pbind2cols
>> # reads a scfile and prints the values generated by a Pbind
>> # Tito Latini
>>
>> use strict;
>> use warnings;
>>
>> usage() if (@ARGV < 1);
>> my ($infile, $events_) = @ARGV;
>>
>> die "$infile absent: $!" unless -e $infile;
>>
>> # sclang server started with:
>> #   socat pty,link=/tmp/sclang.in,echo=0 exec:sclang
>> my $scinput = "/tmp/sclang.in";
>> check_sclang_server($scinput);
>>
>> my $events   = $events_ || 0;
>> my $str      = "";
>> my $str_args = "";
>>
>> my $scfifo   = "/tmp/sclang.out";
>> unless (-p $scfifo) {
>>     use POSIX qw(mkfifo);
>>     unlink $scfifo if -e $scfifo;
>>     mkfifo($scfifo, 0600) or die "mkfifo $scfifo failed: $!";
>> }
>>
>> open(SCL,    ">", $scinput) or die "Could not open $scinput: $!";
>> open(SCFILE, "<", $infile)  or die "Could not open $infile: $!";
>>
>> print SCL "var sclFIFO;\n";
>> while() {
>>     if ($events == 0 && $_ =~ m|//\s+events:\s+(\d+)|) {
>>         $events = ${1};
>>     } elsif ($_ =~ m|//\s+template:\s|) {
>>         my @Ev = split(' ', $_, -1);
>>         foreach my $i (@Ev[2 .. $#Ev]) {
>>             if($i =~ "(.*)<(.*)>(.*)") {
>>                 $str .= "${1}%${3} ";
>>                 $str_args .= ",ev.at(\\${2})";
>>             } else {
>>                 $str .= "${i} ";
>>             }
>>         }
>>         $str = "
>> sclFIFO = File(\"$scfifo\",\"w\");
>> score=score.asStream;
>> $events.do({var ev = score.next(Event.new);
>>   if(ev.notNil, {sclFIFO.write(format(\"${str}\\n\"${str_args}))})});
>> close(sclFIFO)\f
>> ";
>>     } else {
>>         print SCL;
>>     }
>> }
>> print SCL $str;
>>
>> open(FIFO, "<", $scfifo) or die "Could not open $scfifo: $!";
>> print while();
>>
>> sub check_sclang_server {
>>     my ($scinput) = shift;
>>     if (! -e $scinput) {
>>         print STDERR <<"EOF";
>> no sclang server; open a terminal and run
>>
>>   socat pty,link=$scinput,echo=0 exec:sclang
>>
>> EOF
>>     exit(1);
>>     }
>> }
>>
>> sub usage {
>>     print STDERR "Usage: $0 scfile [num-of-events]\n";
>>     exit(1);
>> }
>>
>>
>> Send bugs reports to the Sourceforge bug tracker
>>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
>> Discussions of bugs and features can be posted here
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>>
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>

Date2012-07-08 11:12
FromTito Latini
SubjectRe: [Csnd] Re: patterns CS3 -> Csound alternative
AttachmentsNone  

Date2012-07-08 11:30
FromTito Latini
SubjectRe: [Csnd] Re: patterns CS3 -> Csound alternative
AttachmentsNone  

Date2012-07-08 11:31
Frompeiman khosravi
SubjectRe: [Csnd] Re: patterns CS3 -> Csound alternative
Hi Tito,

OK I'm on OSX. The commands socat & sclang are not recognised.

Best,
P

On 8 July 2012 11:12, Tito Latini  wrote:
>> I tried running your script with your test example `pbind_test.sc'.
>> But nothing happens, the script doesn't return an error but no output
>> is printed.
>
> It works here on GNU/Linux and
>
>   perl 5.10.1
>   socat 1.7.1.3
>   sclang 3.4.5
>
> I suppose problems with Windows but not with OSX (perhaps with pty or
> the form-feed char "\f" in the sclang-code).
> I repeat the steps and you can say (if you want) what it's good and what no:
>
> 1) open a terminal and run
>
>      socat pty,link=/tmp/sclang.in,echo=0 exec:sclang
>
>    The server is listening.
>
> 2) open another terminal and run
>
>      ./scl_pbind2cols.pl pbind_test.sc
>
>    Possibilities (if `socat' works):
>
>      - you get the output
>        -> yeah
>
>      - you don't get the control of the terminal
>        -> problem of the communication with sclang;
>           press CTRL-C to stop the script
>
>      - you get the control of the terminal but no output
>        -> investigate
>
> tito
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>

Date2012-07-08 11:33
Frompeiman khosravi
SubjectRe: [Csnd] Re: patterns CS3 -> Csound alternative
Thanks Tito,

I tried common music and the integration with Csound is limited plus,
timing is not great.

Best,
Peiman

On 8 July 2012 11:30, Tito Latini  wrote:
>> function generator for example). Of course implementing them in python
>> (or in my case I would probably pick clojure at this point) would be
>> much easier than doing the whole thing as csound opcodes.
>
> The patterns in Common Music and/or the ParameterObject in AthenaCL
> are good alternatives.
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>

Date2012-07-08 11:52
FromTito Latini
SubjectRe: [Csnd] Re: patterns CS3 -> Csound alternative
AttachmentsNone  

Date2012-07-08 13:07
Frompeiman khosravi
SubjectRe: [Csnd] Re: patterns CS3 -> Csound alternative
I need to work out how to run sclang from the terminal, this isn't a
default option on OSX. No noise at all! This sounds very harmonious to
my ears ;-)

On 8 July 2012 11:52, Tito Latini  wrote:
>> OK I'm on OSX. The commands socat & sclang are not recognised.
>
> The trick is to use the original patterns of SuperCollider to write
> columns of values. `sclang' is the language of sc and the script
> doesn't work without it. Sorry for the noise and the poor english.
>
> ARP 9000
>
>
> Send bugs reports to the Sourceforge bug tracker
>             https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>