MCPcopy Create free account
hub / github.com/bspaans/python-mingus / Bar

Class Bar

mingus/containers/bar.py:30–261  ·  view source on GitHub ↗

A bar object. A Bar is basically a container for NoteContainers. Bars can be stored together with Instruments in Tracks.

Source from the content-addressed store, hash-verified

28
29
30class 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

Callers 15

MIDI_to_CompositionMethod · 0.90
midi_file_out.pyFile · 0.90
add_notesMethod · 0.90
setUpMethod · 0.90
setUpMethod · 0.90
test_set_itemMethod · 0.90
test_transposeMethod · 0.90
test_augmentMethod · 0.90
test_diminishMethod · 0.90
test_get_note_namesMethod · 0.90
test_determine_chordsMethod · 0.90

Calls

no outgoing calls

Tested by 15

setUpMethod · 0.72
setUpMethod · 0.72
test_set_itemMethod · 0.72
test_transposeMethod · 0.72
test_augmentMethod · 0.72
test_diminishMethod · 0.72
test_get_note_namesMethod · 0.72
test_determine_chordsMethod · 0.72
test_bar_velocityMethod · 0.68
test_playbarMethod · 0.68
test_playbarsMethod · 0.68