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

Class NoteContainer

mingus/containers/note_container.py:27–366  ·  view source on GitHub ↗

A container for notes. The NoteContainer provides a container for the mingus.containers.Note objects. It can be used to store single and multiple notes and is required for working with Bars.

Source from the content-addressed store, hash-verified

25
26
27class NoteContainer(object):
28
29 """A container for notes.
30
31 The NoteContainer provides a container for the mingus.containers.Note
32 objects.
33
34 It can be used to store single and multiple notes and is required for
35 working with Bars.
36 """
37
38 notes = []
39
40 def __init__(self, notes=None):
41 if notes is None:
42 notes = []
43 self.empty()
44 self.add_notes(notes)
45
46 def empty(self):
47 """Empty the container."""
48 self.notes = []
49
50 def add_note(self, note, octave=None, dynamics=None):
51 """Add a note to the container and sorts the notes from low to high.
52
53 The note can either be a string, in which case you could also use
54 the octave and dynamics arguments, or a Note object.
55 """
56 if dynamics is None:
57 dynamics = {}
58 if isinstance(note, six.string_types):
59 if octave is not None:
60 note = Note(note, octave, dynamics)
61 elif len(self.notes) == 0:
62 note = Note(note, 4, dynamics)
63 else:
64 if Note(note, self.notes[-1].octave) < self.notes[-1]:
65 note = Note(note, self.notes[-1].octave + 1, dynamics)
66 else:
67 note = Note(note, self.notes[-1].octave, dynamics)
68 if not hasattr(note, "name"):
69 raise UnexpectedObjectError(
70 "Object '%s' was not expected. "
71 "Expecting a mingus.containers.Note object." % note
72 )
73 if note not in self.notes:
74 self.notes.append(note)
75 self.notes.sort()
76 return self.notes
77
78 def add_notes(self, notes):
79 """Feed notes to self.add_note.
80
81 The notes can either be an other NoteContainer, a list of Note
82 objects or strings or a list of lists formatted like this:
83 >>> notes = [['C', 5], ['E', 5], ['G', 6]]
84

Callers 15

find_chord_fingeringMethod · 0.90
find_note_namesMethod · 0.90
MIDI_to_CompositionMethod · 0.90
midi_file_out.pyFile · 0.90
add_chordMethod · 0.90
place_notesMethod · 0.90
__setitem__Method · 0.90
improviser.pyFile · 0.90
setUpMethod · 0.90

Calls

no outgoing calls

Tested by 15

setUpMethod · 0.72
test_dotted_notesMethod · 0.72
test_to_pdfMethod · 0.72
test_to_pngMethod · 0.72
test_get_rangeMethod · 0.72
test_set_itemMethod · 0.72
setUpMethod · 0.72
test_add_noteMethod · 0.72
test_add_notesMethod · 0.72
test_remove_noteMethod · 0.72