Skip to content

Commit a6d302f

Browse files
authored
fixed MidiPerformance bug where _next_note_index was reset to 0 (#185)
1 parent 112c9ff commit a6d302f

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

backend/data/musicxml/air_on_the_g_string.mid

Whitespace-only changes.

backend/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ def normalize_audio(audio: np.ndarray) -> np.ndarray:
2525
MAX_DURATION = 600 # Maximum duration of audio buffer in seconds
2626

2727

28-
STATED_TEMPO = 220 # Tempo at which the user plans to play in BPM
29-
SOURCE_TEMPO = 200 # Tempo at which the user actually plays in BPM
30-
PIECE_NAME = 'greensleeves' # Name of piece
31-
PROGAM_NUMBER = 0 # Program number for accompaniment instrument
32-
SOLO_VOLUME_MULTIPLIER = 1
28+
STATED_TEMPO = 100 # Tempo at which the user plans to play in BPM
29+
SOURCE_TEMPO = 110 # Tempo at which the user actually plays in BPM
30+
PIECE_NAME = 'air_on_the_g_string' # Name of piece
31+
PROGAM_NUMBER = 42 # Program number for accompaniment instrument
32+
SOLO_VOLUME_MULTIPLIER = 0.75
3333

3434
MIDI_SCORE = os.path.join('data', 'midi', PIECE_NAME + '.mid') # Path to MIDI file
3535
OUTPUT_DIR = os.path.join('data', 'audio', PIECE_NAME) # Directory where synthesized audio will be saved

backend/src/audio_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ def generate_audio(self, output_dir, tempo: float = 120, sample_rate: int = 4410
187187
# Example usage:
188188
base_dir = Path(__file__).parent
189189
score = os.path.join('data', 'midi', 'twinkle_twinkle.mid')
190-
output_dir = os.path.join('data', 'audio', 'twinkle_twinkle', '200bpm')
190+
output_dir = os.path.join('data', 'audio', 'twinkle_twinkle', '100bpm')
191191
SAMPLE_RATE = 44100
192-
TEMPO = 200
192+
TEMPO = 100
193193

194194
try:
195195
generator = AudioGenerator(score_path=score)

backend/src/midi_performance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def update_score_position(self, position: float):
162162
Current position in beats (quarter-note units).
163163
"""
164164
self.score_position = position
165-
self._next_note_index = 0
165+
# self._next_note_index = 0
166166

167167
def _note_worker(self, midi_note: int, duration_sec: float):
168168
"""
@@ -217,7 +217,7 @@ def _performance_loop(self):
217217
while (self._next_note_index < len(self.notes) and
218218
self.score_position >= self.notes[self._next_note_index][2]):
219219
frequency, quarter_duration, quarter_offset = self.notes[self._next_note_index]
220-
if (self.score_position - quarter_offset < .1 and self.last_beat is not quarter_offset):
220+
if (self.score_position - quarter_offset < 1 and self.last_beat is not quarter_offset):
221221
print(
222222
f"Playing note at beat {quarter_offset}: {frequency:.2f} Hz, "
223223
f"duration {quarter_duration} beats"

0 commit comments

Comments
 (0)