A note object. In the mingus.core module, notes are generally represented by strings. Most of the times, this is not enough. We want to set the octave and maybe the amplitude, vibrato or other dynamics. Then we want to store the notes in bars, the bars in tracks, the tracks in compo
| 30 | |
| 31 | |
| 32 | class Note(object): |
| 33 | |
| 34 | """A note object. |
| 35 | |
| 36 | In the mingus.core module, notes are generally represented by strings. |
| 37 | Most of the times, this is not enough. We want to set the octave and |
| 38 | maybe the amplitude, vibrato or other dynamics. Then we want to store |
| 39 | the notes in bars, the bars in tracks, the tracks in compositions, etc. |
| 40 | |
| 41 | We could do this with a number of lists, but ultimately it is a lot |
| 42 | easier to use objects. The Note class provides an easy way to deal with |
| 43 | notes in an object oriented matter. |
| 44 | |
| 45 | You can use the class NoteContainer to group Notes together in intervals |
| 46 | and chords. |
| 47 | """ |
| 48 | |
| 49 | name = _DEFAULT_NAME |
| 50 | octave = _DEFAULT_OCTAVE |
| 51 | channel = _DEFAULT_CHANNEL |
| 52 | velocity = _DEFAULT_VELOCITY |
| 53 | |
| 54 | def __init__(self, name="C", octave=4, dynamics=None, velocity=None, channel=None): |
| 55 | """ |
| 56 | :param name: |
| 57 | :param octave: |
| 58 | :param dynamics: Deprecated. Use `velocity` and `channel` directly. |
| 59 | :param int velocity: Integer (0-127) |
| 60 | :param int channel: Integer (0-15) |
| 61 | """ |
| 62 | if dynamics is None: |
| 63 | dynamics = {} |
| 64 | |
| 65 | if velocity is not None: |
| 66 | dynamics["velocity"] = velocity |
| 67 | if channel is not None: |
| 68 | dynamics["channel"] = channel |
| 69 | |
| 70 | if isinstance(name, six.string_types): |
| 71 | self.set_note(name, octave, dynamics) |
| 72 | elif hasattr(name, "name"): |
| 73 | # Hardcopy Note object |
| 74 | self.set_note(name.name, name.octave, name.dynamics) |
| 75 | elif isinstance(name, int): |
| 76 | self.from_int(name) |
| 77 | else: |
| 78 | raise NoteFormatError("Don't know what to do with name object: %r" % name) |
| 79 | |
| 80 | @property |
| 81 | def dynamics(self): |
| 82 | """ |
| 83 | .. deprecated:: Provided only for compatibility with existing code. |
| 84 | """ |
| 85 | return { |
| 86 | "channel": self.channel, |
| 87 | "velocity": self.velocity, |
| 88 | } |
| 89 |
no outgoing calls