Skip to content

Commit 7bd65be

Browse files
committed
Merge branch 'release/0.4.5'
2 parents cd8cb05 + 74e43fc commit 7bd65be

File tree

6 files changed

+25
-11
lines changed

6 files changed

+25
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [0.4.5] - 2025-09-18
4+
### Fixed
5+
- audio rendering
6+
37
## [0.4.3] - 2025-04-20
48
### Changed
59
- time_shift is no longer an inplace op

fortepyan/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from fortepyan.midi.structures import MidiFile, MidiPiece
55

66
__all__ = ["view", "MidiFile", "MidiPiece"]
7-
__version__ = "0.4.4"
7+
__version__ = "0.4.5"
88

99
# Pretty MIDI will throw an unwanted error for large files with high PPQ
1010
# This is a workaround

fortepyan/audio/render.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ def midi_to_wav(midi: Union[structures.MidiFile, structures.MidiPiece], wavpath:
3535
"""
3636
if isinstance(midi, structures.MidiPiece):
3737
midi = midi.to_midi()
38+
3839
# This will be deleted
3940
tmp_midi_path = tempfile.mkstemp(suffix=".mid")[1]
4041

4142
# Add an silent event to make sure the final notes
4243
# have time to ring out
43-
end_time = midi.get_end_time() + 0.2
44+
end_time = midi.duration + 0.2
4445
pedal_off = pretty_midi.ControlChange(64, 0, end_time)
45-
midi.instruments[0].control_changes.append(pedal_off)
46+
47+
midi._midi.instruments[0].control_changes.append(pedal_off)
4648

4749
midi.write(tmp_midi_path)
4850

fortepyan/midi/structures.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ def time_shift(self, shift_s: float) -> "MidiPiece":
113113
new_piece.df.end += shift_s
114114
return new_piece
115115

116+
@classmethod
117+
def empty(cls) -> "MidiPiece":
118+
df = pd.DataFrame(columns=["start", "duration", "velocity", "pitch"])
119+
piece = cls(df=df)
120+
return piece
121+
116122
def trim(
117123
self,
118124
start: float,
@@ -122,7 +128,7 @@ def trim(
122128

123129
idx = np.where(ids)[0]
124130
if len(idx) == 0:
125-
raise IndexError("No notes found in the specified range.")
131+
return MidiPiece.empty()
126132

127133
start_idx = idx[0]
128134
finish_idx = idx[-1] + 1

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
66

77
[project]
88
name = "fortepyan"
9-
version = "0.4.4"
9+
version = "0.4.5"
1010
description = "Process MIDI piano with (almost) no pain"
1111
readme = "README.md"
1212
authors = [{ name = "Piano For AI", email = "roszcz+fortepyan@gmail.com" }]
@@ -59,7 +59,7 @@ packages = [
5959
]
6060

6161
[tool.bumpver]
62-
current_version = "0.4.4"
62+
current_version = "0.4.5"
6363
version_pattern = "MAJOR.MINOR.PATCH"
6464
commit_message = "bump version {old_version} -> {new_version}"
6565
commit = false

tests/midi/test_structures.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,16 @@ def test_midi_piece_duration_calculation(sample_df):
8787

8888

8989
def test_trim_out_of_bounds(sample_midi_piece):
90-
with pytest.raises(IndexError):
91-
_ = sample_midi_piece.trim(5.5, 8) # Out of bounds, should raise an error
90+
# Out of bounds, should return empty piece
91+
piece = sample_midi_piece.trim(5.5, 8)
92+
assert piece.df.empty
9293

9394

9495
def test_trim_with_invalid_range(sample_midi_piece):
95-
# Assuming the behavior is to raise an error with invalid range
96-
with pytest.raises(IndexError):
97-
_ = sample_midi_piece.trim(4, 2) # Invalid range, start is greater than finish
96+
# Invalid range, start is greater than finish
97+
# Should return empty piece
98+
piece = sample_midi_piece.trim(4, 2)
99+
assert piece.df.empty
98100

99101

100102
def test_to_midi(sample_midi_piece):

0 commit comments

Comments
 (0)