Mercurial > hg > syncopation-dataset
view Syncopation models/MusicObjects.py @ 7:1adcd2267e7e
update musicobjects and rhtyhmparser
author | csong <csong@eecs.qmul.ac.uk> |
---|---|
date | Wed, 01 Apr 2015 22:17:32 +0100 |
parents | ac882f5e6a11 |
children | 2c5df6a4a22f |
line wrap: on
line source
from ParameterSetter import get_subdivision_seq, get_beat_level from RhythmParser import discardSpaces class Note(): def __init__(self, argstring): intlist = map(int,argstring.split(',')) self.startTime = intlist[0] self.duration = intlist[1] self.velocity = intlist[2] # toString() # NoteSequence is a list of Note class NoteSequence(list): def __init__(self, noteSequenceString=None): if noteSequenceString!=None: self.stringToNoteSequence(noteSequenceString) def stringToNoteSequence(self, noteSequenceString): noteSequenceString = 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("),(") for localString in listStrings: self.append(Note(localString)) # toString() print NoteSequence("(1,2,3),(4,5,6),(7,8,9)") # class VelocitySequence(list): # def __init__(self, noteSequenceString=None): # if noteSequenceString!=None: # self.stringToNoteSequence(noteSequenceString) # def stringToNoteSequence(string): 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 self.velocitySequence = None elif isinstance(rhythm_seq, VelocitySequence): self.velocitySequence = rhythm_seq self.noteSequence = None self.tpq = ticks_per_quarter self.qpm = qpm_tempo self.timeSignature = timesig self.nextBar = nextBar self.prevBar = prevBar # def getNoteSequence(self): # if self.noteSequence==None: # self.noteSequence = velocitySequenceToNotes(self.velocitySequence) # return self.noteSequence def getVelocitySequence(self): if self.velocitySequence==None: self.velocitySequence = noteSequenceToVelocities(self.velocitySequence) return self.velocitySequence def getNextBar(self): return self.nextBar def getPreviousBar(self): return self.prevBar def getSubdivisionSequence(self): return get_subdivision_seq(self.timeSignature) def getBeatLevel(self): return get_beat_level(self.timeSignature) def getTimeSignature(self): return self.timeSignature # def getHierarchy(weights): # return None