You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This works for me (tested playing midi to raw files on host computer, as
well as a variant of the nunchuk instrument on pygamer)
it has to re-factor how/when MIDI reading occurs, because reasons.
endorse new test results
.. and allow `-1` to specify a note with no sustain (plucked)
Copy file name to clipboardExpand all lines: shared-bindings/synthio/MidiTrack.c
+8-3Lines changed: 8 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,8 @@
44
44
//| tempo: int,
45
45
//| *,
46
46
//| sample_rate: int = 11025,
47
-
//| waveform: ReadableBuffer = None
47
+
//| waveform: Optional[ReadableBuffer] = None,
48
+
//| envelope: Optional[Envelope] = None,
48
49
//| ) -> None:
49
50
//| """Create a MidiTrack from the given stream of MIDI events. Only "Note On" and "Note Off" events
50
51
//| are supported; channel numbers and key velocities are ignored. Up to two notes may be on at the
@@ -54,6 +55,7 @@
54
55
//| :param int tempo: Tempo of the streamed events, in MIDI ticks per second
55
56
//| :param int sample_rate: The desired playback sample rate; higher sample rate requires more memory
56
57
//| :param ReadableBuffer waveform: A single-cycle waveform. Default is a 50% duty cycle square wave. If specified, must be a ReadableBuffer of type 'h' (signed 16 bit)
58
+
//| :param Envelope envelope: An object that defines the loudness of a note over time. The default envelope provides no ramping, voices turn instantly on and off.
//| At least 2 simultaneous notes are supported. mimxrt10xx and rp2040 platforms support up to
46
-
//| 12 notes.
47
-
//|
48
51
//| Notes use MIDI note numbering, with 60 being C4 or Middle C, approximately 262Hz.
49
52
//|
50
53
//| :param int sample_rate: The desired playback sample rate; higher sample rate requires more memory
51
-
//| :param ReadableBuffer waveform: A single-cycle waveform. Default is a 50% duty cycle square wave. If specified, must be a ReadableBuffer of type 'h' (signed 16 bit). It is permitted to modify this buffer during synthesis. This can be used, for instance, to control the overall volume or timbre of the notes.
54
+
//| :param ReadableBuffer waveform: A single-cycle waveform. Default is a 50% duty cycle square wave. If specified, must be a ReadableBuffer of type 'h' (signed 16 bit)
55
+
//| :param Optional[Envelope] envelope: An object that defines the loudness of a note over time. The default envelope, `None` provides no ramping, voices turn instantly on and off.
//| """The envelope to apply to all notes. `None`, the default envelope, instantly turns notes on and off. The envelope may be changed dynamically, but it affects all notes (even currently playing notes)"""
//| At least 2 simultaneous notes are supported. samd5x, mimxrt10xx and rp2040 platforms support up to 12 notes.
43
+
//|
44
+
//| I'm a little teapot. I'm not on line 11, but I don't know what is.
45
+
//| """
46
+
//|
47
+
//| class Envelope:
48
+
//| def __init__(
49
+
//| self,
50
+
//| attack_time: float,
51
+
//| decay_time: float,
52
+
//| release_time: float,
53
+
//| attack_level: float,
54
+
//| sustain_level: float,
55
+
//| ) -> None:
56
+
//| """Construct an Envelope object
57
+
//|
58
+
//| The Envelope defines an ADSR (Attack, Decay, Sustain, Release) envelope with linear amplitude ramping. A note starts at 0 volume, then increases to ``attack_level`` over ``attack_time`` seconds; then it decays to ``sustain_level`` over ``decay_time`` seconds. Finally, when the note is released, it decreases to ``0`` volume over ``release_time``.
59
+
//|
60
+
//| If the ``sustain_level`` of an envelope is 0, then the decay and sustain phases of the note are always omitted. The note is considered to be released as soon as the envelope reaches the end of the attack phase. The ``decay_time`` is ignored. This is similar to how a plucked or struck instrument behaves.
61
+
//|
62
+
//| If a note is released before it reaches its sustain phase, it decays with the same slope indicated by ``sustain_level/release_time`` (or ``attack_level/release_time`` for plucked envelopes)
63
+
//|
64
+
//| :param float attack_time: The time in seconds it takes to ramp from 0 volume to attack_volume
65
+
//| :param float decay_time: The time in seconds it takes to ramp from attack_volume to sustain_volume
66
+
//| :param float release_time: The time in seconds it takes to ramp from sustain_volume to release_volume. When a note is released before it has reached the sustain phase, the release is done with the same slope indicated by ``release_time`` and ``sustain_level``
67
+
//| :param float attack_level: The relative level, in the range ``0.0`` to ``1.0`` of the peak volume of the attack phase
68
+
//| :param float sustain_level: The relative level, in the range ``0.0`` to ``1.0`` of the volume of the sustain phase
69
+
//| """
70
+
//| attack_time: float
71
+
//| """The time in seconds it takes to ramp from 0 volume to attack_volume"""
72
+
//|
73
+
//| decay_time: float
74
+
//| """The time in seconds it takes to ramp from attack_volume to sustain_volume"""
75
+
//|
76
+
//| release_time: float
77
+
//| """The time in seconds it takes to ramp from sustain_volume to release_volume. When a note is released before it has reached the sustain phase, the release is done with the same slope indicated by ``release_time`` and ``sustain_level``"""
78
+
//|
79
+
//| attack_level: float
80
+
//| """The relative level, in the range ``0.0`` to ``1.0`` of the peak volume of the attack phase"""
81
+
//|
82
+
//| sustain_level: float
83
+
//| """The relative level, in the range ``0.0`` to ``1.0`` of the volume of the sustain phase"""
//| """Create an AudioSample from an already opened MIDI file.
43
139
//| Currently, only single-track MIDI (type 0) is supported.
44
140
//|
45
141
//| :param typing.BinaryIO file: Already opened MIDI file
46
142
//| :param int sample_rate: The desired playback sample rate; higher sample rate requires more memory
47
143
//| :param ReadableBuffer waveform: A single-cycle waveform. Default is a 50% duty cycle square wave. If specified, must be a ReadableBuffer of type 'h' (signed 16 bit)
48
-
//|
144
+
//| :param Envelope envelope: An object that defines the loudness of a note over time. The default envelope provides no ramping, voices turn instantly on and off.
0 commit comments