view Syncopation models/MusicObjects.py @ 6:ac882f5e6a11

adding new bits for midi and music objects
author christopherh <christopher.harte@eecs.qmul.ac.uk>
date Tue, 31 Mar 2015 16:59:45 +0100
parents
children 1adcd2267e7e
line wrap: on
line source

from collections import namedtuple

from ParameterSetter import get_subdivision_seq, get_beat_level

Note = namedtuple('Note', 'startTime duration velocity')

class NoteSequence(list):
	def __init__(self, noteSequenceString=None):
		if noteSequenceString!=None:
			self.stringToNoteSequence(noteSequenceString)

	def stringToNoteSequence(noteSequenceString):



# 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 
		else if 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