Csound Csound-dev Csound-tekno Search About

[Csnd] Re: Re: Python - Help! Creating a nestable "Pattern" class

Date2008-01-05 17:57
From"Michael Gogins"
Subject[Csnd] Re: Re: Python - Help! Creating a nestable "Pattern" class
Have you looked at David Cope's work on algorithmic composition based on 
pattern matching? He gets very remarkable results in terms of automatically 
composing music in existing styles. His code is in Lisp, but most of what 
Lisp does Python can do.

Regards,
Mike

----- Original Message ----- 
From: "Tim Mortimer" 
To: 
Sent: Saturday, January 05, 2008 1:29 AM
Subject: [Csnd] Re: Python - Help! Creating a nestable "Pattern" class


>
> In terms of pattern matching existing patterns to further input, this 
> method
> below is kind of counter-productive..
>
> but in terms of going "the other way around" & building patterns on
> pre-existing motifs, this achieves what i was originally trying to 
> achieve,
> so i thought i may as well post it. (for David W if nobody else...)
>
> (i will be exploring this further, to find the best balance between 
> matching
> "original input" to existing patterns vs. the capacity to "build upon the
> known" as per the below - 2 sides of the coin as it were...)
>
> & I'm not really sure if this is applicable to anything other than 
> rhythms.
> But i still reckon it's pretty cool.
>
> So problem solved! At least by running this, anybody trying to understand
> what i was getting at in the first place may get some more insight...
>
> & David (or anybody) if you have anything more to say on pattern matching 
> or
> the capacity to define unique objects & variables by string concatonation 
> as
> you demonstrated for functions & the use of eval() i'd still be very
> interested.
>
>
> # ******Begin Python Code
>
> dick = {}
>
> dick[-1] = [0,500]
> dick[-2] = [0,750]
> dick[-3] = [-1,-2]
> dick[-4] = [-3,-3]
> dick[-5] = [-4,-3,-2,-1]
>
> def deletedups(valin):
>
>    valout = []
>
>    for e in valin:
>        if e not in valout:
>            valout.append(e)
>
>    return valout
>
> def readdick(index,firstcallflag):
>
>    global dick
>    value = dick[index]
>    resflag = 0
>    valout = []
>
>    while resflag == 0:
>
>        for e in value:
>
>            if e < 0:
>
>                e2 = readdick(e,0)
>                for val in e2:
>                    valout.append(val)
>
>            else:
>
>                valout.append(e)
>
>        resflag = 1
>
>        for val in valout:
>            if val < 0:
>                resflag = 0
>                value = valout
>
>    if firstcallflag == 1:
>
>        # reconcile list for output
>        accum = 0
>        gaccum = 0
>
>        for i in range(len(valout)):
>
>            val = valout[i]
>            #print val
>
>            if val == 0:
>
>                if i == 0:
>                    continue
>
>                gaccum += accum
>                accum = 0
>
>            else:
>
>                accum += val
>                valout[i] = val+gaccum
>
>        valout = deletedups(valout)
>
>    return valout
>
> # ******
>
> keys = dick.keys()
> keys.sort()
> keys.reverse()
>
> print "\nPATTERN DICTIONARY DEMONSTRATION\n"
> print "key: pattern\n"
> for key in keys:
>    pattern = dick[key]
>    print "%s: %s" % (key,pattern)
>
> for key in keys:
>    print "\ncall pattern %s" % key
>    val = readdick(key,1)
>    print val
>
> print "\nthat's how we roll!!\n"
>
> -- 
> View this message in context: 
> http://www.nabble.com/Python---Help%21-Creating-a-nestable-%22Pattern%22-class-tp14564226p14630436.html
> Sent from the Csound - General mailing list archive at Nabble.com.
>
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe 
> csound" 


Date2008-01-06 10:10
FromTim Mortimer
Subject[Csnd] Re: Re: Python - Help! Creating a nestable "Pattern" class
No Michael thanks for the recommendation.

(short Google later...)

http://arts.ucsc.edu/faculty/cope/

That's him? do you know of a specific reference or paper i might find
useful?



Michael Gogins wrote:
> 
> Have you looked at David Cope's work on algorithmic composition based on 
> pattern matching? He gets very remarkable results in terms of
> automatically 
> composing music in existing styles. His code is in Lisp, but most of what 
> Lisp does Python can do.
> 
> Regards,
> Mike
> 
> ----- Original Message ----- 
> From: "Tim Mortimer" 
> To: 
> Sent: Saturday, January 05, 2008 1:29 AM
> Subject: [Csnd] Re: Python - Help! Creating a nestable "Pattern" class
> 
> 
>>
>> In terms of pattern matching existing patterns to further input, this 
>> method
>> below is kind of counter-productive..
>>
>> but in terms of going "the other way around" & building patterns on
>> pre-existing motifs, this achieves what i was originally trying to 
>> achieve,
>> so i thought i may as well post it. (for David W if nobody else...)
>>
>> (i will be exploring this further, to find the best balance between 
>> matching
>> "original input" to existing patterns vs. the capacity to "build upon the
>> known" as per the below - 2 sides of the coin as it were...)
>>
>> & I'm not really sure if this is applicable to anything other than 
>> rhythms.
>> But i still reckon it's pretty cool.
>>
>> So problem solved! At least by running this, anybody trying to understand
>> what i was getting at in the first place may get some more insight...
>>
>> & David (or anybody) if you have anything more to say on pattern matching 
>> or
>> the capacity to define unique objects & variables by string concatonation 
>> as
>> you demonstrated for functions & the use of eval() i'd still be very
>> interested.
>>
>>
>> # ******Begin Python Code
>>
>> dick = {}
>>
>> dick[-1] = [0,500]
>> dick[-2] = [0,750]
>> dick[-3] = [-1,-2]
>> dick[-4] = [-3,-3]
>> dick[-5] = [-4,-3,-2,-1]
>>
>> def deletedups(valin):
>>
>>    valout = []
>>
>>    for e in valin:
>>        if e not in valout:
>>            valout.append(e)
>>
>>    return valout
>>
>> def readdick(index,firstcallflag):
>>
>>    global dick
>>    value = dick[index]
>>    resflag = 0
>>    valout = []
>>
>>    while resflag == 0:
>>
>>        for e in value:
>>
>>            if e < 0:
>>
>>                e2 = readdick(e,0)
>>                for val in e2:
>>                    valout.append(val)
>>
>>            else:
>>
>>                valout.append(e)
>>
>>        resflag = 1
>>
>>        for val in valout:
>>            if val < 0:
>>                resflag = 0
>>                value = valout
>>
>>    if firstcallflag == 1:
>>
>>        # reconcile list for output
>>        accum = 0
>>        gaccum = 0
>>
>>        for i in range(len(valout)):
>>
>>            val = valout[i]
>>            #print val
>>
>>            if val == 0:
>>
>>                if i == 0:
>>                    continue
>>
>>                gaccum += accum
>>                accum = 0
>>
>>            else:
>>
>>                accum += val
>>                valout[i] = val+gaccum
>>
>>        valout = deletedups(valout)
>>
>>    return valout
>>
>> # ******
>>
>> keys = dick.keys()
>> keys.sort()
>> keys.reverse()
>>
>> print "\nPATTERN DICTIONARY DEMONSTRATION\n"
>> print "key: pattern\n"
>> for key in keys:
>>    pattern = dick[key]
>>    print "%s: %s" % (key,pattern)
>>
>> for key in keys:
>>    print "\ncall pattern %s" % key
>>    val = readdick(key,1)
>>    print val
>>
>> print "\nthat's how we roll!!\n"
>>
>> -- 
>> View this message in context: 
>> http://www.nabble.com/Python---Help%21-Creating-a-nestable-%22Pattern%22-class-tp14564226p14630436.html
>> Sent from the Csound - General mailing list archive at Nabble.com.
>>
>>
>>
>> Send bugs reports to this list.
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe 
>> csound" 
> 
> 
> 
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe
> csound"
> 
> 

-- 
View this message in context: http://www.nabble.com/Python---Help%21-Creating-a-nestable-%22Pattern%22-class-tp14564226p14645971.html
Sent from the Csound - General mailing list archive at Nabble.com.


Date2008-01-06 19:02
FromDavidW
Subject[Csnd] Re: Python - Help! Creating a nestable "Pattern" class
Just Google book his name and you can read a few previews.
(Excuse me for butting in)

He's more concerned (at least last time I looked) with style synthesis  
than composition. Excuse my politically incorrect un-post modernism.
I think it is useful to make a distinction between a composer writing  
software as part of the composing process, something written  in order  
to better understand the music of the past, and someone who engineers  
software in the belief that it may be useful to composers. Except in  
the case of low-level or abstract tools, the latter has almost always  
been of limited value in generating original music. I'm not saying  
that the techniques someone like cope employs are not interesting/ 
useful.

It is, IMO one of the great strengths of CS that it is easy to make a  
separation between Church and State in this regard. One can worship at  
the altar with Opcodes when one needs to, and revel in engaging the  
Serpent in Class distinctions the rest of the time, and not be left  
speaking with a lisp.

-drw

On 06/01/2008, at 9:10 PM, Tim Mortimer wrote:

>
> No Michael thanks for the recommendation.
>
> (short Google later...)
>
> http://arts.ucsc.edu/faculty/cope/
>
> That's him? do you know of a specific reference or paper i might find
> useful?
>
>
>
> Michael Gogins wrote:
>>
>> Have you looked at David Cope's work on algorithmic composition  
>> based on
>> pattern matching? He gets very remarkable results in terms of
>> automatically
>> composing music in existing styles. His code is in Lisp, but most  
>> of what
>> Lisp does Python can do.
>>
>> Regards,
>> Mike
>>
>> ----- Original Message -----
>> From: "Tim Mortimer" 
>> To: 
>> Sent: Saturday, January 05, 2008 1:29 AM
>> Subject: [Csnd] Re: Python - Help! Creating a nestable "Pattern"  
>> class
>>
>>
>>>
>>> In terms of pattern matching existing patterns to further input,  
>>> this
>>> method
>>> below is kind of counter-productive..
>>>
>>> but in terms of going "the other way around" & building patterns on
>>> pre-existing motifs, this achieves what i was originally trying to
>>> achieve,
>>> so i thought i may as well post it. (for David W if nobody else...)
>>>
>>> (i will be exploring this further, to find the best balance between
>>> matching
>>> "original input" to existing patterns vs. the capacity to "build  
>>> upon the
>>> known" as per the below - 2 sides of the coin as it were...)
>>>
>>> & I'm not really sure if this is applicable to anything other than
>>> rhythms.
>>> But i still reckon it's pretty cool.
>>>
>>> So problem solved! At least by running this, anybody trying to  
>>> understand
>>> what i was getting at in the first place may get some more  
>>> insight...
>>>
>>> & David (or anybody) if you have anything more to say on pattern  
>>> matching
>>> or
>>> the capacity to define unique objects & variables by string  
>>> concatonation
>>> as
>>> you demonstrated for functions & the use of eval() i'd still be very
>>> interested.
>>>
>>>
>>> # ******Begin Python Code
>>>
>>> dick = {}
>>>
>>> dick[-1] = [0,500]
>>> dick[-2] = [0,750]
>>> dick[-3] = [-1,-2]
>>> dick[-4] = [-3,-3]
>>> dick[-5] = [-4,-3,-2,-1]
>>>
>>> def deletedups(valin):
>>>
>>> valout = []
>>>
>>> for e in valin:
>>>  if e not in valout:
>>>      valout.append(e)
>>>
>>> return valout
>>>
>>> def readdick(index,firstcallflag):
>>>
>>> global dick
>>> value = dick[index]
>>> resflag = 0
>>> valout = []
>>>
>>> while resflag == 0:
>>>
>>>  for e in value:
>>>
>>>      if e < 0:
>>>
>>>          e2 = readdick(e,0)
>>>          for val in e2:
>>>              valout.append(val)
>>>
>>>      else:
>>>
>>>          valout.append(e)
>>>
>>>  resflag = 1
>>>
>>>  for val in valout:
>>>      if val < 0:
>>>          resflag = 0
>>>          value = valout
>>>
>>> if firstcallflag == 1:
>>>
>>>  # reconcile list for output
>>>  accum = 0
>>>  gaccum = 0
>>>
>>>  for i in range(len(valout)):
>>>
>>>      val = valout[i]
>>>      #print val
>>>
>>>      if val == 0:
>>>
>>>          if i == 0:
>>>              continue
>>>
>>>          gaccum += accum
>>>          accum = 0
>>>
>>>      else:
>>>
>>>          accum += val
>>>          valout[i] = val+gaccum
>>>
>>>  valout = deletedups(valout)
>>>
>>> return valout
>>>
>>> # ******
>>>
>>> keys = dick.keys()
>>> keys.sort()
>>> keys.reverse()
>>>
>>> print "\nPATTERN DICTIONARY DEMONSTRATION\n"
>>> print "key: pattern\n"
>>> for key in keys:
>>> pattern = dick[key]
>>> print "%s: %s" % (key,pattern)
>>>
>>> for key in keys:
>>> print "\ncall pattern %s" % key
>>> val = readdick(key,1)
>>> print val
>>>
>>> print "\nthat's how we roll!!\n"
>>>
>>> ...

_________________________________________________
experimental polymedia:	www.avatar.com.au
Sonic Communications Research Group,
University of Canberra:	 creative.canberra.edu.au/scrg/


_________________________________________________
experimental polymedia:	www.avatar.com.au
Sonic Communications Research Group,
University of Canberra:	 creative.canberra.edu.au/scrg/



Date2008-01-07 00:36
FromTim Mortimer
Subject[Csnd] Re: Python - Help! Creating a nestable "Pattern" class
Thank you both very much gentlemen.

Yes i'm not sure i'd be interested in using anything "out the box" anyway at
this stage - esp. if it wasn't hackable. (although if the Holy Grail did
exist, I would no doubt be interested.... That's my Parseval "slogan" after
all - "The Holy Grail of Sequencing" - catchy huh! ; ) 

But i would be interested in reading anything that explains some techniques
for identifying "patterns" in larger "datasets". 

If similar motifs & developmental strategies recur from piece to piece i
guess that constitutes a "style". Style could be more concerned with surface
veneer & production values though these days.... Putting PVOC sounds &
drones in every piece could also be constituted as a "style"... My
terminology tends to be fairly ad-hoc however. (but i did Architecture for 2
years, so I recall enough all this to at least realise i probably have no
idea what i'm talking about when it comes to PM.)

In essence I am considering algorithmically identifying patterns, with the
intention of "hand crafting" variations. Reduction to the "atomic" level
(with reference to your Paper Michael G) is a useful approach therefore it
seems not only computationally but compositionally. So any style under
potentially broader analysis would be my own. (assuming i have any - 95% of
the music i have written to date are 4 minute pop songs - hoping that
Parseval will help me try & organise something a bit larger, & to make them
instrumental...I'm over lyrics - especially writing them)

Rest assured David - I'm always very happy when you butt in. It looks as if
we can start feeling less guilty about our blather in general.

& thank you again Michael. I always appreciate any time you have to offer
some guidance & insight. Lest we forget that this list & the internet are my
sole sources of information here. (tear down the JSTOR firewall i say! ; )
......)



David Worrall wrote:
> 
> Just Google book his name and you can read a few previews.
> (Excuse me for butting in)
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Python---Help%21-Creating-a-nestable-%22Pattern%22-class-tp14564226p14656413.html
Sent from the Csound - General mailing list archive at Nabble.com.


Date2008-01-07 11:23
From"Oeyvind Brandtsegg"
Subject[Csnd] Re: Re: Python - Help! Creating a nestable "Pattern" class
AttachmentsNone