예제 #1
0
def onset(position, metadata):
  """Calculate the ideal onset of this position given the tempo in metadata"""
  scale = 1000000
  m = meter.getMeter(metadata)
  bpm = metadata['bpm']
  beatlength = scale/(bpm/60.0)
  beats = position / float(m.quarters_per_beat())
  return beats * beatlength
예제 #2
0
 def __init__(self, annotation, notes, metadata):
     from jazzr.rhythm import meter
     self.annotation = annotation
     self.notes = notes
     self.metadata = metadata
     self.bpm = metadata['bpm']
     self.name = metadata['name']
     self.meter = meter.getMeter(metadata)
     # Onset units per second (1000000 = onsets in microseconds)
     self.scale = 1000000
예제 #3
0
def deviation(position, onset, metadata):
  """Calculate the proportion of a beat that the given onset deviates
  from the ideal onset corresponding to the given position."""
  # Onset units per second (1000000 = onsets in microseconds)
  scale = 1000000
  m = meter.getMeter(metadata)
  bpm = metadata['bpm']
  beatlength = scale/(bpm/60.0)
  beats = position / float(m.quarters_per_beat())
  beat_onset = beats * beatlength
  deviation = onset - beat_onset
  return deviation / beatlength
예제 #4
0
def split(annotation, index, metadata):
  """Split notes and rests that span across multiple bars in separate
  (bound) notes and rests."""
  (position, x, pitch, type) = annotation[index]
  m = meter.getMeter(metadata)
  if not type in [types.REST, types.NOTE]:
    return [(position, index, pitch, type)]
  ql = quarterLength(annotation, index, metadata)
  current = position
  remainder = ql
  result = []
  barlength = m.quarters_per_bar()
  while bar(current, metadata) != bar(current + remainder, metadata):
    diff = (bar(current, metadata)+1)*barlength - current
    result.append((current, index, pitch, type))
    remainder -= diff
    current += diff
  if remainder > 0:
    result.append((current, index, pitch, type))
  return result
예제 #5
0
def barposition(position, metadata):
  """Calculate the position in quarter notes relative to the 
  beginning of the bar."""
  m = meter.getMeter(metadata)
  beats = position / float(m.quarters_per_beat())
  return beats - m.beatspb * (beats // m.beatspb)
예제 #6
0
def bar(position, metadata):
  """Return the bar in which this position occurs"""
  m = meter.getMeter(metadata)
  beats = position / float(m.quarters_per_beat())
  return int(beats // m.beatspb)