# HG changeset patch # User christopherh # Date 1427929617 -3600 # Node ID 2c5df6a4a22faf7fdf4d93451dee508b5935b39a # Parent 1adcd2267e7e411259978d7c0cfd3d9fe721fee3 updated music objects, removed old bar definition from rhythm parser diff -r 1adcd2267e7e -r 2c5df6a4a22f Syncopation models/MusicObjects.py --- a/Syncopation models/MusicObjects.py Wed Apr 01 22:17:32 2015 +0100 +++ b/Syncopation models/MusicObjects.py Thu Apr 02 00:06:57 2015 +0100 @@ -1,8 +1,8 @@ +from BasicFuncs import ceiling -from ParameterSetter import get_subdivision_seq, get_beat_level - -from RhythmParser import discardSpaces +import ParameterSetter +import RhythmParser class Note(): def __init__(self, argstring): @@ -17,10 +17,10 @@ class NoteSequence(list): def __init__(self, noteSequenceString=None): if noteSequenceString!=None: - self.stringToNoteSequence(noteSequenceString) + self.string_to_note_sequence(noteSequenceString) - def stringToNoteSequence(self, noteSequenceString): - noteSequenceString = discardSpaces(noteSequenceString) + def string_to_note_sequence(self, noteSequenceString): + noteSequenceString = RhythmParser.discardSpaces(noteSequenceString) # try: # Turning "(1,2,3),(4,5,6),(7,8,9)" into ["1,2,3","4,5,6,","7,8,9"] listStrings = noteSequenceString[1:-1].split("),(") @@ -34,51 +34,71 @@ # class VelocitySequence(list): # def __init__(self, noteSequenceString=None): # if noteSequenceString!=None: -# self.stringToNoteSequence(noteSequenceString) +# self.string_to_note_sequence(noteSequenceString) -# def stringToNoteSequence(string): +# def string_to_note_sequence(string): + + +class BarList(list): + def append(self,bar): + if(len(self)>0): + bar.set_previous_bar(self[-1]) + self[-1].set_next_bar(bar) + super(BarList, self).append(bar) + class Bar: - def __init__(self, rhythm_seq, timesig, ticks_per_quarter=None, qpm_tempo=None, nextBar=None, prevBar=None): - if isinstance(rhythm_seq, NoteSequence): - self.noteSequence = rhythm_seq + def __init__(self, rhythmSequence, timeSignature, ticksPerQuarter=None, qpmTempo=None, nextBar=None, prevBar=None): + if isinstance(rhythmSequence, NoteSequence): + self.noteSequence = rhythmSequence self.velocitySequence = None - elif isinstance(rhythm_seq, VelocitySequence): - self.velocitySequence = rhythm_seq + elif isinstance(rhythmSequence, VelocitySequence): + self.velocitySequence = rhythmSequence self.noteSequence = None - self.tpq = ticks_per_quarter - self.qpm = qpm_tempo - self.timeSignature = timesig + self.tpq = ticksPerQuarter + self.qpm = qpmTempo + self.timeSignature = timeSignature self.nextBar = nextBar self.prevBar = prevBar - # def getNoteSequence(self): - # if self.noteSequence==None: - # self.noteSequence = velocitySequenceToNotes(self.velocitySequence) - # return self.noteSequence + def get_note_sequence(self): + #if self.noteSequence==None: + # self.noteSequence = velocitySequenceToNotes(self.velocitySequence) + return self.noteSequence - def getVelocitySequence(self): + def get_velocity_sequence(self): if self.velocitySequence==None: self.velocitySequence = noteSequenceToVelocities(self.velocitySequence) return self.velocitySequence - def getNextBar(self): + def get_binary_sequence(self): + return ceiling(self.get_velocity_sequence()) + + def get_next_bar(self): return self.nextBar - def getPreviousBar(self): + def get_previous_bar(self): return self.prevBar - def getSubdivisionSequence(self): - return get_subdivision_seq(self.timeSignature) + def set_next_bar(self, bar): + self.nextBar = bar - def getBeatLevel(self): - return get_beat_level(self.timeSignature) + def set_previous_bar(self, bar): + self.prevBar = bar - def getTimeSignature(self): + def get_subdivision_sequence(self): + return ParameterSetter.get_subdivision_seq(self.timeSignature) + + def get_beat_level(self): + return ParameterSetter.get_beat_level(self.timeSignature) + + def get_time_signature(self): return self.timeSignature -# def getHierarchy(weights): -# return None + def get_t_span(self): + # return the length of a bar in time units + return None # NEED TO IMPLEMENT + diff -r 1adcd2267e7e -r 2c5df6a4a22f Syncopation models/RhythmParser.py --- a/Syncopation models/RhythmParser.py Wed Apr 01 22:17:32 2015 +0100 +++ b/Syncopation models/RhythmParser.py Thu Apr 02 00:06:57 2015 +0100 @@ -8,15 +8,6 @@ from ParameterSetter import timesigBase -class Bar: - - def __init__(self, rhythm_seq, subdivision_seq, beat_level): - self.rhythm_seq = rhythm_seq - self.subdivision_seq = subdivision_seq - self.beat_level = beat_level - - - comment_sign = '#' def discardComments(line): diff -r 1adcd2267e7e -r 2c5df6a4a22f Syncopation models/text_bnf_syntax.txt --- a/Syncopation models/text_bnf_syntax.txt Wed Apr 01 22:17:32 2015 +0100 +++ b/Syncopation models/text_bnf_syntax.txt Thu Apr 02 00:06:57 2015 +0100 @@ -5,9 +5,9 @@ ::= "TPQ{" "}" - ::= [] ["#" ] "\n" + ::= [] ["#" ] "\n" - ::= | [] | + ::= | [] | ::= [] [] []