`music21.midi.MidiEvent.getBytes()` confuses `SEQUENCER_SPECIFIC_META_EVENT` (0x7F) with `POLY_MODE_ON` (also 0x7F)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python
- Lĩnh vực
- audio-video-rtc
Hướng nghiên cứu
The bug is in getBytes() in music21/midi/init.py, which dispatches on the raw enum value so SEQUENCER_SPECIFIC_META_EVENT (0x7F) matches ChannelModeMessages.POLY_MODE_ON and crashes when channel is None. Reproduce with the snippet in the issue, then make the branch checks also verify the enum class of self.type. Done when the snippet no longer raises and a MidiFile read-then-write round trip succeeds.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
music21 version
9.5.0
Operating System(s) checked
OS agnostic
(I am on Ubuntu 24.04, though, but that should be irrelevant.)
Problem summary
music21.midi.MidiEvent.getBytes() confuses SEQUENCER_SPECIFIC_META_EVENT (0x7F) with POLY_MODE_ON (also 0x7F) and will therefore cause a TypeError if the former does not care about channels (i.e self.channel == None).
Steps to reproduce
from music21 import midi
ev = midi.MidiEvent(type=midi.MetaEvents.SEQUENCER_SPECIFIC_META_EVENT, channel=None)
print(ev)
b = ev.getBytes()
FYI: Actually I encountered this issue not by instantiating a MidiEvent manually but by writing a MidiFile which comes with some SEQUENCER_SPECIFIC_META_EVENT's.
mf = midi.MidiFile()
mf.open(inputfile)
mf.read()
mf.close()
# write the contents back immediately without touching anything
mf.open(outputfile, 'wb')
mf.write()
mf.close()
Expected vs. actual behavior
EXPECTED BEHAVIOUR:
music21.midi.MidiEvent.getBytes() should process all MIDI events correctly without triggering any exception.
ACTUAL BEHAVIOUR:
File "/foo/bar/lib/python3.12/site-packages/music21/midi/__init__.py", line 982, in getBytes
channelMode = bytes([0xB0 + self.channel - 1])
~~~~~^~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
More information
The current code of music21.midi.MidiEvent.getBytes() checks the event type essentially by looking at its value only:
def getBytes(self):
if self.type in ChannelVoiceMessages:
...
elif self.type in ChannelModeMessages:
channelMode = bytes([0xB0 + self.channel - 1])
...
elif self.type in SysExEvents:
...
elif self.type in MetaEvents:
...
else:
...
However:
class ChannelModeMessages(_ContainsEnum):
...
POLY_MODE_ON = 0x7F
...
class MetaEvents(_ContainsEnum):
...
SEQUENCER_SPECIFIC_META_EVENT = 0x7F
...
Apparently, getBytes() will mistake a SEQUENCER_SPECIFIC_META_EVENT as a POLY_MODE_ON, and will then fail immediately if self.channel is null.
Therefore, it is probably more appropriate to also check the event class, in addition to the event type value:
if isinstance(self.type, ChannelVoiceMessages) and self.type in ChannelVoiceMessages:
...
elif isinstance(self.type, ChannelModeMessages) and self.type in ChannelModeMessages:
...
elif isinstance(self.type, SysExEvents) and self.type in SysExEvents:
...
elif isinstance(self.type, MetaEvents) and self.type in MetaEvents:
...
- Ngôn ngữ chính
- Python
- Star
- 2.6k
- Fork
- 459
- Merge trung bình
- 1 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 40
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của cuthbertLab/music21
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
cuthbertLab/music21#2084 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
cuthbertLab/music21#2082 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`TypeError` in `ChordReducer.run()` on multi-part `stream.Score` without instrument `partId`sĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
cuthbertLab/music21#2074 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
cuthbertLab/music21#2055 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Slur bezier-x/y from start element gets overwritten by stop element's valuesCó thể làm lại được @bingliscodes đã nhận 10 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
cuthbertLab/music21#2019 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của cuthbertLab/music21
Issue tương tự
-
docs: the dev-setup table and AGENTS.md name the reviewed_by guard that CI's Changelog job runsĐang mởarea: tools documentation good first issue ready for a contributor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
eyalgolan/statecraft-israel#873 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add cover art to song rowsĐang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 5 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày