Skip to content

Commit e0d7c3b

Browse files
committed
Improve documentation about Note.dynamics deprecation and constructor
1 parent f7092b6 commit e0d7c3b

4 files changed

Lines changed: 51 additions & 15 deletions

File tree

doc/wiki/refMingusContainersNote.rst

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ mingus.containers.note
1919
.. method:: __gt__(self, other)
2020

2121

22-
.. method:: __init__(self, name=C, octave=4, dynamics={})
22+
.. method:: __init__(self, name=C, octave=4, dynamics=None, velocity=None, channel=None)
23+
24+
:param name:
25+
:param octave:
26+
:param dynamics: Deprecated. Use `velocity` and `channel` directly.
27+
:param velocity:
28+
:param channel:
2329

2430

2531
.. method:: __int__(self)
@@ -152,13 +158,26 @@ mingus.containers.note
152158
Call notes.remove_redundant_accidentals on this note's name.
153159

154160

155-
.. method:: set_note(self, name=C, octave=4, dynamics={})
161+
.. method:: set_channel(self, channel)
162+
163+
164+
.. method:: set_note(self, name=C, octave=4, dynamics=None, velocity=None, channel=None)
156165

157166
Set the note to name in octave with dynamics.
158167

159168
Return the objects if it succeeded, raise an NoteFormatError
160169
otherwise.
161170

171+
:param name:
172+
:param octave:
173+
:param dynamics: Deprecated. Use `velocity` and `channel` directly.
174+
:param velocity:
175+
:param channel:
176+
:return:
177+
178+
179+
.. method:: set_velocity(self, velocity)
180+
162181

163182
.. method:: to_hertz(self, standard_pitch=440)
164183

mingus/containers/note.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ class Note(object):
5252
velocity = _DEFAULT_VELOCITY
5353

5454
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+
"""
5562
if dynamics is None:
5663
dynamics = {}
5764

@@ -68,12 +75,13 @@ def __init__(self, name="C", octave=4, dynamics=None, velocity=None, channel=Non
6875
elif isinstance(name, int):
6976
self.from_int(name)
7077
else:
71-
raise NoteFormatError(
72-
"Don't know what to do with name object: " "'%s'" % name
73-
)
78+
raise NoteFormatError("Don't know what to do with name object: %r" % name)
7479

7580
@property
7681
def dynamics(self):
82+
"""
83+
.. deprecated:: Provided only for compatibility with existing code.
84+
"""
7785
return {
7886
"channel": self.channel,
7987
"velocity": self.velocity,
@@ -94,6 +102,13 @@ def set_note(self, name="C", octave=4, dynamics=None, velocity=None, channel=Non
94102
95103
Return the objects if it succeeded, raise an NoteFormatError
96104
otherwise.
105+
106+
:param name:
107+
:param octave:
108+
:param dynamics: Deprecated. Use `velocity` and `channel` directly.
109+
:param int velocity: Integer (0-127)
110+
:param int channel: Integer (0-15)
111+
:return:
97112
"""
98113
if dynamics is None:
99114
dynamics = {}
@@ -115,22 +130,17 @@ def set_note(self, name="C", octave=4, dynamics=None, velocity=None, channel=Non
115130
self.octave = octave
116131
return self
117132
else:
118-
raise NoteFormatError(
119-
"The string '%s' is not a valid "
120-
"representation of a note in mingus" % name
121-
)
133+
raise NoteFormatError("Invalid note representation: %r" % name)
122134
elif len(dash_index) == 2:
123135
note, octave = dash_index
124136
if notes.is_valid_note(note):
125137
self.name = note
126138
self.octave = int(octave)
127139
return self
128140
else:
129-
raise NoteFormatError(
130-
"The string '%s' is not a valid "
131-
"representation of a note in mingus" % name
132-
)
133-
return False
141+
raise NoteFormatError("Invalid note representation: %r" % name)
142+
else:
143+
raise NoteFormatError("Invalid note representation: %r" % name)
134144

135145
def empty(self):
136146
"""Remove the data in the instance."""

mingus/containers/note_container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def add_notes(self, notes):
8383
>>> notes = [['C', 5], ['E', 5], ['G', 6]]
8484
8585
or even:
86-
>>> notes = [['C', 5, {'volume': 20}], ['E', 6, {'volume': 20}]]
86+
>>> notes = [['C', 5, {'velocity': 20}], ['E', 6, {'velocity': 20}]]
8787
"""
8888
if hasattr(notes, "notes"):
8989
for x in notes.notes:

tests/unit/containers/test_note_containers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import
33

4+
import doctest
45
import unittest
56

7+
import mingus.containers.note_container
68
from mingus.containers.note import Note
79
from mingus.containers.note_container import NoteContainer
810

@@ -135,3 +137,8 @@ def test_is_dissonant(self):
135137
self.assertTrue(not NoteContainer().from_chord("C").is_dissonant())
136138
self.assertTrue(not NoteContainer().from_chord("G").is_dissonant())
137139
self.assertTrue(not NoteContainer().from_chord("Dm").is_dissonant())
140+
141+
142+
def load_tests(loader, tests, ignore):
143+
tests.addTests(doctest.DocTestSuite(mingus.containers.note_container))
144+
return tests

0 commit comments

Comments
 (0)