diff --git a/share/instruments/instruments.xml b/share/instruments/instruments.xml index 3d7cbfc9059e9..5f713e9c14ebb 100644 --- a/share/instruments/instruments.xml +++ b/share/instruments/instruments.xml @@ -7308,7 +7308,7 @@ drums - + Large Drum Kit Drum Kit D. Kit diff --git a/share/instruments/update_instruments_xml.py b/share/instruments/update_instruments_xml.py index abbefc24c56db..afc2d48436099 100755 --- a/share/instruments/update_instruments_xml.py +++ b/share/instruments/update_instruments_xml.py @@ -34,6 +34,7 @@ def eprint(*args, **kwargs): import csv import io import os +import re import requests import sys import xml.etree.ElementTree as ET @@ -54,6 +55,8 @@ def eprint(*args, **kwargs): 'GM+GS_Percussion': '1216482735', } +standard_drumset_id = 'drumset' + parser = argparse.ArgumentParser(description='Fetch the latest spreadsheet and generate instruments.xml.') parser.add_argument('-c', '--cached', action='store_true', help='Use cached version instead of downloading') parser.add_argument('-d', '--download', action='append', choices=sheet_ids.keys(), help='Override cached option for a specific sheet') @@ -293,7 +296,7 @@ def to_list(str): to_subelement(el, instrument, 'transpDia', 'transposeDiatonic') to_subelement(el, instrument, 'transpChr', 'transposeChromatic') - if instrument['id'] in drumsets: + if instrument['id'] != standard_drumset_id and instrument['id'] in drumsets: for drum in drumsets[instrument['id']].values(): pitch = drum['pitch'] d_el = ET.SubElement(el, 'Drum') @@ -498,3 +501,68 @@ def get_comment(instrument, nameType: str, hasTrait: bool): ordersTree = ET.parse('orders.xml') for order in ordersTree.getroot().findall('Order'): add_translatable_string(f, 'engraving/scoreorder', order.find('name').text) + +def noteheadgroup(tag): + if tag == 'altbrevis': + return 'HEAD_BREVIS_ALT' + + if re.match(r'^[a-h](-sharp|-flat)?-name$', tag): + tag = tag[:-5] # remove '-name' from end of tag + + return 'HEAD_' + tag.upper().replace('-', '_') + +# Generate the standard drumset. This must be hard-coded in C++ to ensure it's +# available at startup when systems are initialized (engraving, playback, MIDI +# & MusicXML import), which happens prior to instruments.xml being loaded. +standard_drumset_cpp_path = '../../src/engraving/dom/drumset.cpp' +gen_code = '' + +for drum in drumsets[standard_drumset_id].values(): + pitch = drum['pitch'] + head = 'HEAD_' + drum['head'].upper().replace('-', '_') + stem = 'DOWN' if drum['stem'] == '2' else 'UP' + + shortcut = drum['shortcut'] + shortcut = 'Key_' + shortcut if shortcut and shortcut != null else '0' + + gen_code += f""" + // {drum['drum']} + smDrumset->drum({pitch}) = DrumInstrument( + TConv::userName(DrumNum({pitch})), + NoteHeadGroup::{noteheadgroup(drum['head'])}, + /*line*/ {drum['line']}, + DirectionV::{stem}, + /*panelRow*/ {drum['row']}, + /*panelColumn*/ {drum['col']}, + /*voice*/ {drum['voice']}, + /*shortcut*/ {shortcut}); +""" + +with open(standard_drumset_cpp_path, newline='\n', encoding='utf-8') as file: + old_code = file.read() + +old_lines = old_code.split('\n') +begin_line = -1 +end_line = -1 +new_code = '' + +for num, line in enumerate(old_lines, 1): + if 'BEGIN GENERATED CODE' in line: + begin_line = num + break + +assert begin_line > 0 + +for num, line in enumerate(old_lines[begin_line:], 1): + if 'END GENERATED CODE' in line: + end_line = begin_line + num + break + +assert end_line > begin_line + +new_code = '\n'.join(old_lines[:begin_line]) + f'\n{gen_code}\n' + '\n'.join(old_lines[end_line-1:]) + +if new_code != old_code: + eprint('Writing ' + standard_drumset_cpp_path) + with open(standard_drumset_cpp_path, 'w', newline='\n', encoding='utf-8') as file: + file.write(new_code) diff --git a/src/engraving/dom/drumset.cpp b/src/engraving/dom/drumset.cpp index 7cfd382ac646a..e5172695a5817 100644 --- a/src/engraving/dom/drumset.cpp +++ b/src/engraving/dom/drumset.cpp @@ -292,96 +292,269 @@ void Drumset::initDrumset() smDrumset->drum(i).panelRow = -1; smDrumset->drum(i).panelColumn = -1; } + + // Code generated by share/instruments/update_instruments_xml.py. To edit this code: + // 1. Make your changes in the proper place: + // * To change instrument data, edit the online spreadsheet. + // * For other code changes, edit the Python script. + // 2. Run the Python script to generate the changes here. + // 3. Run Uncrustify and update the Python script if necessary to match Uncrustify's formatting. + + // BEGIN GENERATED CODE + // Acoustic Bass Drum - smDrumset->drum(35) = DrumInstrument(TConv::userName(DrumNum(35)), NoteHeadGroup::HEAD_NORMAL, /*line*/ 8, DirectionV::DOWN, - /*panelRow*/ 2, /*panelColumn*/ 1, /*voice*/ 1); + smDrumset->drum(35) = DrumInstrument( + TConv::userName(DrumNum(35)), + NoteHeadGroup::HEAD_NORMAL, + /*line*/ 8, + DirectionV::DOWN, + /*panelRow*/ 2, + /*panelColumn*/ 1, + /*voice*/ 1, + /*shortcut*/ 0); // Bass Drum 1 - smDrumset->drum(36) = DrumInstrument(TConv::userName(DrumNum(36)), NoteHeadGroup::HEAD_NORMAL, /*line*/ 7, DirectionV::DOWN, - /*panelRow*/ 2, /*panelColumn*/ 0, /*voice*/ 1, Key_B); + smDrumset->drum(36) = DrumInstrument( + TConv::userName(DrumNum(36)), + NoteHeadGroup::HEAD_NORMAL, + /*line*/ 7, + DirectionV::DOWN, + /*panelRow*/ 2, + /*panelColumn*/ 0, + /*voice*/ 1, + /*shortcut*/ Key_B); // Side Stick - smDrumset->drum(37) = DrumInstrument(TConv::userName(DrumNum(37)), NoteHeadGroup::HEAD_SLASHED1, /*line*/ 3, DirectionV::UP, - /*panelRow*/ 1, /*panelColumn*/ 1); + smDrumset->drum(37) = DrumInstrument( + TConv::userName(DrumNum(37)), + NoteHeadGroup::HEAD_SLASHED1, + /*line*/ 3, + DirectionV::UP, + /*panelRow*/ 1, + /*panelColumn*/ 1, + /*voice*/ 0, + /*shortcut*/ 0); // Acoustic Snare - smDrumset->drum(38) = DrumInstrument(TConv::userName(DrumNum(38)), NoteHeadGroup::HEAD_NORMAL, /*line*/ 3, DirectionV::UP, - /*panelRow*/ 1, /*panelColumn*/ 0, /*voice*/ 0, Key_A); + smDrumset->drum(38) = DrumInstrument( + TConv::userName(DrumNum(38)), + NoteHeadGroup::HEAD_NORMAL, + /*line*/ 3, + DirectionV::UP, + /*panelRow*/ 1, + /*panelColumn*/ 0, + /*voice*/ 0, + /*shortcut*/ Key_A); // Electric Snare - smDrumset->drum(40) = DrumInstrument(TConv::userName(DrumNum(40)), NoteHeadGroup::HEAD_SLASH, /*line*/ 3, DirectionV::UP, - /*panelRow*/ 2, /*panelColumn*/ 6); + smDrumset->drum(40) = DrumInstrument( + TConv::userName(DrumNum(40)), + NoteHeadGroup::HEAD_SLASH, + /*line*/ 3, + DirectionV::UP, + /*panelRow*/ 2, + /*panelColumn*/ 6, + /*voice*/ 0, + /*shortcut*/ 0); // Low Floor Tom - smDrumset->drum(41) = DrumInstrument(TConv::userName(DrumNum(41)), NoteHeadGroup::HEAD_NORMAL, /*line*/ 6, DirectionV::UP, - /*panelRow*/ 1, /*panelColumn*/ 7); + smDrumset->drum(41) = DrumInstrument( + TConv::userName(DrumNum(41)), + NoteHeadGroup::HEAD_NORMAL, + /*line*/ 6, + DirectionV::UP, + /*panelRow*/ 1, + /*panelColumn*/ 7, + /*voice*/ 0, + /*shortcut*/ 0); // Closed Hi-Hat - smDrumset->drum(42) = DrumInstrument(TConv::userName(DrumNum(42)), NoteHeadGroup::HEAD_CROSS, /*line*/ -1, DirectionV::UP, - /*panelRow*/ 0, /*panelColumn*/ 0, /*voice*/ 0, Key_G); + smDrumset->drum(42) = DrumInstrument( + TConv::userName(DrumNum(42)), + NoteHeadGroup::HEAD_CROSS, + /*line*/ -1, + DirectionV::UP, + /*panelRow*/ 0, + /*panelColumn*/ 0, + /*voice*/ 0, + /*shortcut*/ Key_G); // High Floor Tom - smDrumset->drum(43) = DrumInstrument(TConv::userName(DrumNum(43)), NoteHeadGroup::HEAD_NORMAL, /*line*/ 5, DirectionV::UP, - /*panelRow*/ 1, /*panelColumn*/ 6); + smDrumset->drum(43) = DrumInstrument( + TConv::userName(DrumNum(43)), + NoteHeadGroup::HEAD_NORMAL, + /*line*/ 5, + DirectionV::UP, + /*panelRow*/ 1, + /*panelColumn*/ 6, + /*voice*/ 0, + /*shortcut*/ 0); // Pedal Hi-Hat - smDrumset->drum(44) = DrumInstrument(TConv::userName(DrumNum(44)), NoteHeadGroup::HEAD_CROSS, /*line*/ 9, DirectionV::DOWN, - /*panelRow*/ 2, /*panelColumn*/ 2, /*voice*/ 1, Key_F); + smDrumset->drum(44) = DrumInstrument( + TConv::userName(DrumNum(44)), + NoteHeadGroup::HEAD_CROSS, + /*line*/ 9, + DirectionV::DOWN, + /*panelRow*/ 2, + /*panelColumn*/ 2, + /*voice*/ 1, + /*shortcut*/ Key_F); // Low Tom - smDrumset->drum(45) = DrumInstrument(TConv::userName(DrumNum(45)), NoteHeadGroup::HEAD_NORMAL, /*line*/ 4, DirectionV::UP, - /*panelRow*/ 1, /*panelColumn*/ 5); + smDrumset->drum(45) = DrumInstrument( + TConv::userName(DrumNum(45)), + NoteHeadGroup::HEAD_NORMAL, + /*line*/ 4, + DirectionV::UP, + /*panelRow*/ 1, + /*panelColumn*/ 5, + /*voice*/ 0, + /*shortcut*/ 0); // Open Hi-Hat - smDrumset->drum(46) = DrumInstrument(TConv::userName(DrumNum(46)), NoteHeadGroup::HEAD_XCIRCLE, /*line*/ -1, DirectionV::UP, - /*panelRow*/ 0, /*panelColumn*/ 1); + smDrumset->drum(46) = DrumInstrument( + TConv::userName(DrumNum(46)), + NoteHeadGroup::HEAD_XCIRCLE, + /*line*/ -1, + DirectionV::UP, + /*panelRow*/ 0, + /*panelColumn*/ 1, + /*voice*/ 0, + /*shortcut*/ 0); // Low-Mid Tom - smDrumset->drum(47) = DrumInstrument(TConv::userName(DrumNum(47)), NoteHeadGroup::HEAD_NORMAL, /*line*/ 2, DirectionV::UP, - /*panelRow*/ 1, /*panelColumn*/ 4); + smDrumset->drum(47) = DrumInstrument( + TConv::userName(DrumNum(47)), + NoteHeadGroup::HEAD_NORMAL, + /*line*/ 2, + DirectionV::UP, + /*panelRow*/ 1, + /*panelColumn*/ 4, + /*voice*/ 0, + /*shortcut*/ 0); // Hi-Mid Tom - smDrumset->drum(48) = DrumInstrument(TConv::userName(DrumNum(48)), NoteHeadGroup::HEAD_NORMAL, /*line*/ 1, DirectionV::UP, - /*panelRow*/ 1, /*panelColumn*/ 3); + smDrumset->drum(48) = DrumInstrument( + TConv::userName(DrumNum(48)), + NoteHeadGroup::HEAD_NORMAL, + /*line*/ 1, + DirectionV::UP, + /*panelRow*/ 1, + /*panelColumn*/ 3, + /*voice*/ 0, + /*shortcut*/ 0); // Crash Cymbal 1 - smDrumset->drum(49) = DrumInstrument(TConv::userName(DrumNum(49)), NoteHeadGroup::HEAD_CROSS, /*line*/ -2, DirectionV::UP, - /*panelRow*/ 0, /*panelColumn*/ 4, /*voice*/ 0, Key_C); + smDrumset->drum(49) = DrumInstrument( + TConv::userName(DrumNum(49)), + NoteHeadGroup::HEAD_CROSS, + /*line*/ -2, + DirectionV::UP, + /*panelRow*/ 0, + /*panelColumn*/ 4, + /*voice*/ 0, + /*shortcut*/ Key_C); // High Tom - smDrumset->drum(50) = DrumInstrument(TConv::userName(DrumNum(50)), NoteHeadGroup::HEAD_NORMAL, /*line*/ 0, DirectionV::UP, - /*panelRow*/ 1, /*panelColumn*/ 2, /*voice*/ 0, Key_E); + smDrumset->drum(50) = DrumInstrument( + TConv::userName(DrumNum(50)), + NoteHeadGroup::HEAD_NORMAL, + /*line*/ 0, + DirectionV::UP, + /*panelRow*/ 1, + /*panelColumn*/ 2, + /*voice*/ 0, + /*shortcut*/ Key_E); // Ride Cymbal 1 - smDrumset->drum(51) = DrumInstrument(TConv::userName(DrumNum(51)), NoteHeadGroup::HEAD_CROSS, /*line*/ 0, DirectionV::UP, - /*panelRow*/ 0, /*panelColumn*/ 2, /*voice*/ 0, Key_D); + smDrumset->drum(51) = DrumInstrument( + TConv::userName(DrumNum(51)), + NoteHeadGroup::HEAD_CROSS, + /*line*/ 0, + DirectionV::UP, + /*panelRow*/ 0, + /*panelColumn*/ 2, + /*voice*/ 0, + /*shortcut*/ Key_D); // Chinese Cymbal - smDrumset->drum(52) = DrumInstrument(TConv::userName(DrumNum(52)), NoteHeadGroup::HEAD_CROSS, /*line*/ -4, DirectionV::UP, - /*panelRow*/ 0, /*panelColumn*/ 6); + smDrumset->drum(52) = DrumInstrument( + TConv::userName(DrumNum(52)), + NoteHeadGroup::HEAD_CROSS, + /*line*/ -4, + DirectionV::UP, + /*panelRow*/ 0, + /*panelColumn*/ 6, + /*voice*/ 0, + /*shortcut*/ 0); // Ride Bell - smDrumset->drum(53) = DrumInstrument(TConv::userName(DrumNum(53)), NoteHeadGroup::HEAD_DIAMOND, /*line*/ 0, DirectionV::UP, - /*panelRow*/ 0, /*panelColumn*/ 3); + smDrumset->drum(53) = DrumInstrument( + TConv::userName(DrumNum(53)), + NoteHeadGroup::HEAD_DIAMOND, + /*line*/ 0, + DirectionV::UP, + /*panelRow*/ 0, + /*panelColumn*/ 3, + /*voice*/ 0, + /*shortcut*/ 0); // Tambourine - smDrumset->drum(54) = DrumInstrument(TConv::userName(DrumNum(54)), NoteHeadGroup::HEAD_DIAMOND, /*line*/ 1, DirectionV::UP, - /*panelRow*/ 2, /*panelColumn*/ 4); + smDrumset->drum(54) = DrumInstrument( + TConv::userName(DrumNum(54)), + NoteHeadGroup::HEAD_DIAMOND, + /*line*/ 1, + DirectionV::UP, + /*panelRow*/ 2, + /*panelColumn*/ 4, + /*voice*/ 0, + /*shortcut*/ 0); // Splash Cymbal - smDrumset->drum(55) = DrumInstrument(TConv::userName(DrumNum(55)), NoteHeadGroup::HEAD_CROSS, /*line*/ -5, DirectionV::UP, - /*panelRow*/ 0, /*panelColumn*/ 7); + smDrumset->drum(55) = DrumInstrument( + TConv::userName(DrumNum(55)), + NoteHeadGroup::HEAD_CROSS, + /*line*/ -5, + DirectionV::UP, + /*panelRow*/ 0, + /*panelColumn*/ 7, + /*voice*/ 0, + /*shortcut*/ 0); // Cowbell - smDrumset->drum(56) = DrumInstrument(TConv::userName(DrumNum(56)), NoteHeadGroup::HEAD_TRIANGLE_DOWN, /*line*/ 1, DirectionV::UP, - /*panelRow*/ 2, /*panelColumn*/ 3); + smDrumset->drum(56) = DrumInstrument( + TConv::userName(DrumNum(56)), + NoteHeadGroup::HEAD_TRIANGLE_DOWN, + /*line*/ 1, + DirectionV::UP, + /*panelRow*/ 2, + /*panelColumn*/ 3, + /*voice*/ 0, + /*shortcut*/ 0); // Crash Cymbal 2 - smDrumset->drum(57) = DrumInstrument(TConv::userName(DrumNum(57)), NoteHeadGroup::HEAD_CROSS, /*line*/ -3, DirectionV::UP, - /*panelRow*/ 0, /*panelColumn*/ 5); + smDrumset->drum(57) = DrumInstrument( + TConv::userName(DrumNum(57)), + NoteHeadGroup::HEAD_CROSS, + /*line*/ -3, + DirectionV::UP, + /*panelRow*/ 0, + /*panelColumn*/ 5, + /*voice*/ 0, + /*shortcut*/ 0); // Ride Cymbal 2 - smDrumset->drum(59) = DrumInstrument(TConv::userName(DrumNum(59)), NoteHeadGroup::HEAD_CROSS, /*line*/ 2, DirectionV::UP, - /*panelRow*/ 2, /*panelColumn*/ 5); + smDrumset->drum(59) = DrumInstrument( + TConv::userName(DrumNum(59)), + NoteHeadGroup::HEAD_CROSS, + /*line*/ 2, + DirectionV::UP, + /*panelRow*/ 2, + /*panelColumn*/ 5, + /*voice*/ 0, + /*shortcut*/ 0); + + // END GENERATED CODE } }