Mercurial > hg > syncopation-dataset
changeset 8:2c5df6a4a22f
updated music objects, removed old bar definition from rhythm
parser
author | christopherh <christopher.harte@eecs.qmul.ac.uk> |
---|---|
date | Thu, 02 Apr 2015 00:06:57 +0100 |
parents | 1adcd2267e7e |
children | c2843ef4de2c |
files | Syncopation models/MusicObjects.py Syncopation models/RhythmParser.py Syncopation models/text_bnf_syntax.txt |
diffstat | 3 files changed, 52 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- 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 +
--- 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):
--- 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 @@ <ticks per quarter> ::= "TPQ{" <digits> "}" -<line> ::= [<bars>] ["#" <comment-text>] "\n" +<line> ::= [<barlist>] ["#" <comment-text>] "\n" -<bars> ::= <time-info> | [<time-info>] <bar> | <bars> <bar> +<barlist> ::= <time-info> | [<time-info>] <bar> | <barlist> <bar> <time-info> ::= [<timesig>] [<ticks per quarter>] [<tempo>]