Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

MusicXML import drops piano-family MIDI programs when the instrument name isn't recognized

Đang mở Phù hợp với người mới
#2,084 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
data

Hướng nghiên cứu

Lỗi nằm ở phần xử lý score-part của MeasureParser trong musicxml/xmlToM21.py, nơi thay thế nhóm piano làm mất midiProgram khi tên nhạc cụ không được nhận dạng. Chạy script tái hiện trong issue để thấy Instrument có midiProgram là None với chương trình 1 và 2. Hoàn thành khi chương trình 1 và 2 giữ midiProgram lần lượt là 0 và 1, và chương trình 41 vẫn trả về Violin với giá trị 40. Chọn một cách sửa: hoặc chỉ thay thế khi tên được nhận dạng, hoặc sao chép i.midiProgram sang phần thay thế, rồi thêm một test hồi quy cạnh các test phân tích MusicXML hiện có.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

music21 version

10.5.0

Problem summary

When a part's <midi-program> is one music21 maps to Piano (MusicXML programs 1–6), the importer replaces that instrument with the one made from <instrument-name>. That makes sense when the name is recognized, since exporters often write piano as a default program. But when the name isn't recognized, the replacement is a plain Instrument with no midiProgram, so the program is lost. Other programs are kept.

Steps to reproduce

from music21 import converter, instrument

def score(midi_program):
    return f'''<score-partwise version="4.0">
  <part-list><score-part id="P1"><part-name>Music</part-name>
    <score-instrument id="P1-I1"><instrument-name>Doubler</instrument-name></score-instrument>
    <midi-instrument id="P1-I1"><midi-program>{midi_program}</midi-program></midi-instrument>
  </score-part></part-list>
  <part id="P1"><measure number="1">
    <attributes><divisions>1</divisions></attributes>
    <note><pitch><step>C</step><octave>4</octave></pitch><duration>4</duration><type>whole</type></note>
  </measure></part>
</score-partwise>'''

for midi_program in (41, 1, 2):
    parsed = converter.parse(score(midi_program), format='musicxml')
    print(midi_program, [(type(i).__name__, i.midiProgram)
                         for i in parsed.recurse().getElementsByClass(instrument.Instrument)])

Expected vs. actual behavior

Expected a midiProgram of 40, 0 and 1. Actual:

41 [('Violin', 40)]
1 [('Instrument', None)]
2 [('Instrument', None)]

More information

The replacement is in MeasureParser's score-part handling (musicxml/xmlToM21.py):

# 2. midiProgram is Piano (often this is encoded only as piano for convenience)
if inst_from_name.midiProgram == i.midiProgram or isinstance(i, instrument.Piano):
    i = inst_from_name

This isn't asking to remove the piano rule, only to not lose the program when the name doesn't give an instrument, for example by only replacing when the name was recognized, or by keeping i.midiProgram on the replacement.

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

Mở trong Codespaces

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.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của cuthbertLab/music21

Tất cả issue của cuthbertLab/music21

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.