view Syncopation models/MeterStructure.py @ 0:76ce27beba95

Have uploaded the syncopation dataset and audio wavefies.
author Chunyang Song <csong@eecs.qmul.ac.uk>
date Fri, 21 Mar 2014 15:49:46 +0000
parents
children
line wrap: on
line source
'''
Author: Chunyang Song
Institution: Centre for Digital Music, Queen Mary University of London

** Meter Structure **

This class defines metrical hierarchy for a few common-used time-signature, including 2/4, 4/4, 3/4, 6/8.
All methods return results to represent corresponding information for defined number of bars.
The getLJWeights() adopts Lerdahl and Jackendoff metrical hierarchy. The lowest level is the 16th-note level, whose weight is 1. The highest level is bar level. 
The getLHLWeights() adopts Louguet-Higgins and Lee metrical hierarchy, which is basically the same as L&J but in negative scale. The highest level is weighted as 0.
The getStrongBeat() is to select the locations of the beats. For example, in 4/4, "strong" beats are all quarter-notes.

**** To be added in: getPKWeights()

'''
class MeterStructure:

	def __init__(self,time_sig): # meter hierarchy for 1 bar
		self.ts = time_sig
	
	def getLJWeights(self,bar):	
		self.lj = []
		if '2/4' in self.ts:
			self.lj = [4,1,2,1,3,1,2,1]*bar
		elif '4/4' in self.ts:
			self.lj = [5,1,2,1,3,1,2,1,4,1,2,1,3,1,2,1]*bar
		elif '3/4' in self.ts:
			self.lj = [4,1,2,1,3,1,2,1,3,1,2,1]*bar
		elif '6/8' in self.ts:
			self.lj = [4,1,2,1,2,1,3,1,2,1,2,1]*bar
		else:
			print 'The range of time-signature is limited within {2/4, 4/4, 3/4, 6/8}'
		return self.lj

	def getLHLWeights(self,bar):
		self.lhl = []
		# lhl weights are the same numbers moved from the 
		lj = self.getLJWeights(bar)
		if len(lj) !=0:
			downbeat = max(lj)
			for i in lj:
				self.lhl.append(i-downbeat)
		else:
			print 'The range of time-signature is limited within {2/4, 4/4, 3/4, 6/8}'
		return self.lhl

	def getPKWeights(self,bar):
		self.pk = []
		'''
			...
		'''
		return self.pk

	def getBeats(self,bar):     
		self.Beats = []		
		if '2/4' in self.ts:            # Strong beats in one bar in 2/4 are every quarter-note [0,24]
			for i in range(2*bar):
				self.Beats.append(i*24)
		elif '4/4' in self.ts:          # Strong beats in one bar 4/4 are every quarter-note [0,12,24,36]
			for i in range(4*bar):
				self.Beats.append(i*12)
		elif '3/4'in self.ts:			# Strong beats in one bar in 3/4 are every quarter-note [0,16,32]
			for i in range(3*bar):
				self.Beats.append(i*16)
		elif '6/8' in self.ts:			# Strong beats in one bar in 6/8 are every three eighth-note [0,24]
			for i in range(2*bar):
				self.Beats.append(i*24)
		else:
			print 'The range of time-signature is limited within {2/4, 4/4, 3/4, 6/8}'
		return self.Beats

	def getCircle(self,bar):
		self.circle = []
		if '2/4' in self.ts:
			self.circle = range(8)*bar             # 2/4 meter can be represented by 8-unit-circle (in one bar)
		elif '4/4' in self.ts:
			self.circle = range(16)*bar            # 4/4 meter can be represented by 16-unit-circle (in one bar)
		elif '3/4' or '6/8' in self.ts:
			self.circle = range(12)*bar            # 3/4 or 6/8 meter can be represented by 12-unit-circle (in one bar)
		else:
			print 'The range of time-signature is limited within {2/4, 4/4, 3/4, 6/8}'
		return self.circle