A bar object. A Bar is basically a container for NoteContainers. Bars can be stored together with Instruments in Tracks.
| 28 | |
| 29 | |
| 30 | class Bar(object): |
| 31 | """A bar object. |
| 32 | |
| 33 | A Bar is basically a container for NoteContainers. |
| 34 | |
| 35 | Bars can be stored together with Instruments in Tracks. |
| 36 | """ |
| 37 | |
| 38 | key = "C" |
| 39 | meter = (4, 4) |
| 40 | current_beat = 0.0 |
| 41 | length = 0.0 |
| 42 | bar = [] |
| 43 | |
| 44 | def __init__(self, key="C", meter=(4, 4)): |
| 45 | # warning should check types |
| 46 | if isinstance(key, six.string_types): |
| 47 | key = keys.Key(key) |
| 48 | self.key = key |
| 49 | self.set_meter(meter) |
| 50 | self.empty() |
| 51 | |
| 52 | def empty(self): |
| 53 | """Empty the Bar, remove all the NoteContainers.""" |
| 54 | self.bar = [] |
| 55 | self.current_beat = 0.0 |
| 56 | return self.bar |
| 57 | |
| 58 | def set_meter(self, meter): |
| 59 | """Set the meter of this bar. |
| 60 | |
| 61 | Meters in mingus are represented by a single tuple. |
| 62 | |
| 63 | If the format of the meter is not recognised, a MeterFormatError |
| 64 | will be raised. |
| 65 | """ |
| 66 | # warning should raise exception |
| 67 | if _meter.valid_beat_duration(meter[1]): |
| 68 | self.meter = (meter[0], meter[1]) |
| 69 | self.length = meter[0] * (1.0 / meter[1]) |
| 70 | elif meter == (0, 0): |
| 71 | self.meter = (0, 0) |
| 72 | self.length = 0.0 |
| 73 | else: |
| 74 | raise MeterFormatError( |
| 75 | "The meter argument '%s' is not an " |
| 76 | "understood representation of a meter. " |
| 77 | "Expecting a tuple." % meter |
| 78 | ) |
| 79 | |
| 80 | def place_notes(self, notes, duration): |
| 81 | """Place the notes on the current_beat. |
| 82 | |
| 83 | Notes can be strings, Notes, list of strings, list of Notes or a |
| 84 | NoteContainer. |
| 85 | |
| 86 | Raise a MeterFormatError if the duration is not valid. |
| 87 |
no outgoing calls