diff --git a/README.md b/README.md index 35c97b7d..d57a123f 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,8 @@ This table is generated from `docs/data/supported-synths.yml` by `scripts/genera | Yamaha | FS1R | alpha | adaptation | 2.10.2 | Thanks to @markusschlosser for testing! | | Yamaha | reface DX | works | adaptation | 2.10.2 | | | Yamaha | reface CP | beta | adaptation | 2.10.2 | Thanks to @milnak! | +| Yamaha | SY77 (voices) | beta | adaptation | After 2.10.2 | Contributed by @hmmbug and Giovanni Candiago. Original SY77 hardware testing by @hmmbug. | +| Yamaha | TG77 (voices) | beta | adaptation | After 2.10.2 | Contributed by @hmmbug and Giovanni Candiago. Original TG77 hardware testing by Giovanni Candiago. | | Yamaha | TX7 | works | adaptation | 2.10.2 | Thanks to Gerome S! | | Yamaha | TX81Z | works | adaptation | 2.10.2 | Contributed by @summersetter! | | Yamaha | Yamaha YC61/YC73/YC88 | works | adaptation | 2.10.2 | Thanks to @milnak! | diff --git a/The-Orm/CMakeLists.txt b/The-Orm/CMakeLists.txt index eabfbf3a..022db981 100644 --- a/The-Orm/CMakeLists.txt +++ b/The-Orm/CMakeLists.txt @@ -277,6 +277,12 @@ add_custom_command(TARGET KnobKraftOrm POST_BUILD -DNO_PYCACHE_DEST_DIR=$/korg -P ${CMAKE_SOURCE_DIR}/cmake/copy_without_pycache.cmake ) +add_custom_command(TARGET KnobKraftOrm POST_BUILD + COMMAND ${CMAKE_COMMAND} + -DNO_PYCACHE_SOURCE_DIR=${CMAKE_SOURCE_DIR}/adaptations/yamaha + -DNO_PYCACHE_DEST_DIR=$/yamaha + -P ${CMAKE_SOURCE_DIR}/cmake/copy_without_pycache.cmake + ) add_custom_command(TARGET KnobKraftOrm POST_BUILD COMMAND ${CMAKE_COMMAND} -DNO_PYCACHE_SOURCE_DIR=${CMAKE_SOURCE_DIR}/adaptations/knobkraft diff --git a/The-Orm/setup.iss b/The-Orm/setup.iss index c8e0e75a..a8f84794 100644 --- a/The-Orm/setup.iss +++ b/The-Orm/setup.iss @@ -50,6 +50,7 @@ Source: "${CMAKE_CURRENT_BINARY_DIR}\RelWithDebInfo\WinSparkle.dll"; DestDir: "{ Source: "${CMAKE_SOURCE_DIR}\adaptations\sequential\*.*"; DestDir: "{app}\sequential";Flags: ignoreversion Source: "${CMAKE_SOURCE_DIR}\adaptations\roland\*.*"; DestDir: "{app}\roland";Flags: ignoreversion Source: "${CMAKE_SOURCE_DIR}\adaptations\korg\*.*"; DestDir: "{app}\korg";Flags: ignoreversion +Source: "${CMAKE_SOURCE_DIR}\adaptations\yamaha\*.py"; DestDir: "{app}\yamaha";Flags: ignoreversion Source: "${CMAKE_SOURCE_DIR}\adaptations\knobkraft\*.*"; DestDir: "{app}\knobkraft";Flags: ignoreversion Source: "${CMAKE_SOURCE_DIR}\adaptations\testing\*.*"; DestDir: "{app}\testing";Flags: ignoreversion #include "adaptations.iss" @@ -66,6 +67,9 @@ Type: dirifempty; Name: "{app}\roland" Type: files; Name: "{app}\korg\__pycache__\*.pyc" Type: dirifempty; Name: "{app}\korg\__pycache__" Type: dirifempty; Name: "{app}\korg" +Type: files; Name: "{app}\yamaha\__pycache__\*.pyc" +Type: dirifempty; Name: "{app}\yamaha\__pycache__" +Type: dirifempty; Name: "{app}\yamaha" Type: files; Name: "{app}\knobkraft\__pycache__\*.pyc" Type: dirifempty; Name: "{app}\knobkraft\__pycache__" Type: dirifempty; Name: "{app}\knobkraft" diff --git a/adaptations/CMakeLists.txt b/adaptations/CMakeLists.txt index f2a473a9..b464f7d0 100644 --- a/adaptations/CMakeLists.txt +++ b/adaptations/CMakeLists.txt @@ -35,7 +35,7 @@ set(adaptation_files "Sequential_Fourm.py" "Sequential Pro 3.py" "Sequential Prophet 5 Rev4.py" "Sequential Prophet 6.py" "Sequential Prophet X.py" "Sequential_Take_5.py" "Sequential_Trigon6.py" "Studiologic Sledge.py" "Waldorf Blofeld.py" "Waldorf_Kyra.py" "Waldorf_MicroWave.py" "Waldorf_M.py" "Waldorf_Pulse.py" - "YamahaDX7.py" "YamahaDX7II.py" "Yamaha_TX7.py" "Yamaha_FS1R.py" "YamahaRefaceDX.py" "YamahaRefaceCP.py" "Yamaha_TX81Z.py" "Yamaha-YC-Series.py" + "YamahaDX7.py" "YamahaDX7II.py" "Yamaha_TX7.py" "Yamaha_FS1R.py" "YamahaRefaceDX.py" "YamahaRefaceCP.py" "Yamaha_TX81Z.py" "Yamaha-YC-Series.py" "Yamaha_SY77.py" "Yamaha_TG77.py" "Zoom_MS.py" ) @@ -60,6 +60,7 @@ set(adaptation_files_test_shipped "test_Sequential_Fourm.py" "test_Sequential_Pro_3.py" "test_YamahaRefaceDX.py" + "test_Yamaha_SY77_TG77.py" ) set(adaptation_files_test_only @@ -71,6 +72,7 @@ set(adaptation_files_test_only set(adaptation_support_files "roland/__init__.py" "roland/GenericRoland.py" "sequential/__init__.py" "sequential/GenericSequential.py" + "yamaha/__init__.py" "yamaha/Yamaha77Voice.py" "knobkraft/__init__.py" "knobkraft/adaptation_module.py" "knobkraft/sysex.py" "knobkraft/test_helper.py" "korg/__init__.py" "korg/GenericKorg.py" "testing/__init__.py" "testing/test_data.py" @@ -129,6 +131,7 @@ if(UNIX AND NOT APPLE) # Define additional install files - in our case, all adaptation files and the python modules install(DIRECTORY sequential/ DESTINATION bin/sequential PATTERN "__pycache__" EXCLUDE) install(DIRECTORY roland/ DESTINATION bin/roland PATTERN "__pycache__" EXCLUDE) + install(DIRECTORY yamaha/ DESTINATION bin/yamaha PATTERN "__pycache__" EXCLUDE) install(DIRECTORY korg/ DESTINATION bin/korg PATTERN "__pycache__" EXCLUDE) install(DIRECTORY knobkraft/ DESTINATION bin/knobkraft PATTERN "__pycache__" EXCLUDE) install(DIRECTORY testing/ DESTINATION bin/testing PATTERN "__pycache__" EXCLUDE) diff --git a/adaptations/Yamaha_SY77.py b/adaptations/Yamaha_SY77.py new file mode 100644 index 00000000..17e528bb --- /dev/null +++ b/adaptations/Yamaha_SY77.py @@ -0,0 +1,14 @@ +"""Yamaha SY77 voices. Initial adaptation and ROM 1.5 hardware testing by hmmbug.""" + +from yamaha.Yamaha77Voice import Yamaha77Voice, voice_test_data + +Yamaha77Voice("SY77", "GrandPiano").install(globals()) + + +def make_test_data(): + return voice_test_data("testData/Yamaha_SY77/bank.syx", 64, [ + (0, "GrandPiano", "IN-A01"), + (6, "Triton", "IN-A07"), + (7, "FrenchHorn", "IN-A08"), + (16, "Dyna Grand", "IN-B01"), + ]) diff --git a/adaptations/Yamaha_TG77.py b/adaptations/Yamaha_TG77.py new file mode 100644 index 00000000..849fc816 --- /dev/null +++ b/adaptations/Yamaha_TG77.py @@ -0,0 +1,29 @@ +"""Yamaha TG77 voices. Initial adaptation by hmmbug and Giovanni Candiago. +TG77 hardware testing and all-voice-mode fixture by Giovanni Candiago. +""" + +from yamaha.Yamaha77Voice import Yamaha77Voice, voice_test_data + +Yamaha77Voice("TG77", "SP|Cosmo").install(globals()) + + +def generalMessageDelay(): + # Giovanni measured up to 800 ms for the 1564-byte 4AFM mono dump. + return 800 + + +def make_test_data(): + return voice_test_data("testData/Yamaha_SY77-TG77/TG77_test_voices.syx", 75, [ + (0, "PD:PUFF AT", "IN-A01"), + (2, "PD:WARM", "IN-A03"), + (4, "PD:CHRSTRG", "IN-A05"), + (6, "WN:PICCOLO", "IN-A07"), + (12, "PD:GB AGE", "IN-A13"), + (19, "PD:PUFF AT", "IN-B04"), + (48, "PD:OPET", "IN-D01"), + ], mode_samples=[ + (64, "1AFM mono"), (65, "2AFM mono"), (66, "4AFM mono"), + (67, "1AFM poly"), (68, "2AFM poly"), (69, "1AWM poly"), + (70, "2AWM poly"), (71, "4AWM poly"), (72, "1AFM&1AWM"), + (73, "2AFM&2AWM"), (74, "Drum Set"), + ]) diff --git a/adaptations/testData/Yamaha_SY77-TG77/TG77_test_voices.syx b/adaptations/testData/Yamaha_SY77-TG77/TG77_test_voices.syx new file mode 100644 index 00000000..d7f92d06 Binary files /dev/null and b/adaptations/testData/Yamaha_SY77-TG77/TG77_test_voices.syx differ diff --git a/adaptations/testData/Yamaha_SY77/bank.syx b/adaptations/testData/Yamaha_SY77/bank.syx new file mode 100644 index 00000000..153ebaee Binary files /dev/null and b/adaptations/testData/Yamaha_SY77/bank.syx differ diff --git a/adaptations/testData/Yamaha_TG77/Preset1.syx b/adaptations/testData/Yamaha_TG77/Preset1.syx new file mode 100644 index 00000000..cf72678f Binary files /dev/null and b/adaptations/testData/Yamaha_TG77/Preset1.syx differ diff --git a/adaptations/testData/Yamaha_TG77/Preset1_01_SP_Cosmo__.syx b/adaptations/testData/Yamaha_TG77/Preset1_01_SP_Cosmo__.syx new file mode 100644 index 00000000..ec0bb395 Binary files /dev/null and b/adaptations/testData/Yamaha_TG77/Preset1_01_SP_Cosmo__.syx differ diff --git a/adaptations/test_Yamaha_SY77_TG77.py b/adaptations/test_Yamaha_SY77_TG77.py new file mode 100644 index 00000000..a6deaafc --- /dev/null +++ b/adaptations/test_Yamaha_SY77_TG77.py @@ -0,0 +1,192 @@ +from pathlib import Path + +import knobkraft +import pytest + +import Yamaha_SY77 as sy77 +import Yamaha_TG77 as tg77 +from yamaha.Yamaha77Voice import Yamaha77Voice + + +FIXTURES = Path(__file__).parent / "testData" +SY77_INTERNAL = "Yamaha_SY77/bank.syx" +TG77_PRESETS = "Yamaha_TG77/Preset1.syx" +TG77_PRESET_ONE = "Yamaha_TG77/Preset1_01_SP_Cosmo__.syx" +TG77_INTERNAL = "Yamaha_SY77-TG77/TG77_test_voices.syx" + + +def _system_reply(device, voice_channel): + payload = [*b"LM 8101SY", *([0] * 80)] + payload[80 - 6] = voice_channel + return [0xF0, 0x43, device, 0x7A, 0, 90, *payload, (-sum(payload)) & 0x7F, 0xF7] + + +def _with_memory(voice, device, memory, slot): + result = voice.copy() + result[2] = device + result[30:32] = [memory, slot] + result[-2] = (-sum(result[6:-2])) & 0x7F + return result + + +@pytest.mark.parametrize("module", [sy77, tg77]) +@pytest.mark.parametrize("file,count", [ + (SY77_INTERNAL, 64), (TG77_PRESETS, 64), (TG77_PRESET_ONE, 1), (TG77_INTERNAL, 75), +]) +def test_both_models_import_all_captured_voices(module, file, count): + voices = knobkraft.load_sysex(str(FIXTURES / file)) + assert len(voices) == count + for voice in voices: + expected_program = (64 if voice[30] == 2 else 0) + voice[31] + assert module.isSingleProgramDump(voice) + assert not module.isEditBufferDump(voice) + assert module.numberFromDump(voice) == expected_program + edit = module.convertToEditBuffer(11, voice) + assert module.isEditBufferDump(edit) + assert not module.isSingleProgramDump(edit) + assert edit[2] == 11 + assert module.calculateFingerprint(edit) == module.calculateFingerprint(voice) + + +@pytest.mark.parametrize("system_first", [True, False]) +@pytest.mark.parametrize("name,first_preset,other_preset,file,other_file", [ + ("SY77", "GrandPiano", "SP|Cosmo", SY77_INTERNAL, TG77_PRESET_ONE), + ("TG77", "SP|Cosmo", "GrandPiano", TG77_PRESET_ONE, SY77_INTERNAL), +]) +def test_detection_matches_only_its_factory_voice_and_learns_midi_channel( + system_first, name, first_preset, other_preset, file, other_file): + synth = Yamaha77Voice(name, first_preset) + device = 15 + for address in range(16): + assert knobkraft.splitSysex(synth.createDeviceDetectMessage(address)) == [ + [0xF0, 0x43, 0x20 | address, 0x7A, *b"LM 8101VC", + *([0] * 14), 2, 0, 0xF7], + [0xF0, 0x43, 0x20 | address, 0x7A, *b"LM 8101SY", + *([0] * 16), 0xF7], + ] + + system = _system_reply(device, 8) + # The SY77 hardware reply uses the edit-buffer address for the requested preset. + # The TG77 preset file stands in for a factory preset reply in this test. + model_data = knobkraft.load_sysex(str(FIXTURES / file))[0] + match = _with_memory(model_data, device, 0x7F if name == "SY77" else 2, 0) + other_data = knobkraft.load_sysex(str(FIXTURES / other_file))[0] + wrong_model = _with_memory(other_data, device, 2, 0) + assert synth.channelIfValidDeviceResponse(wrong_model) == -1 + + replies = [(system, -1), (match, device)] + for message, expected in replies if system_first else reversed(replies): + assert synth.channelIfValidDeviceResponse(message) == expected + + expected_pc = [0xC8, 122, 0xC8, 17] if name == "SY77" else [0xC8, 17] + assert synth.createCustomProgramChange(device, 17) == expected_pc + + other = Yamaha77Voice("TG77" if name == "SY77" else "SY77", other_preset) + other.createDeviceDetectMessage(device) + assert other.channelIfValidDeviceResponse(system) == -1 + assert other.channelIfValidDeviceResponse(match) == -1 + + +def test_system_reply_alone_cannot_replace_an_identified_devices_voice_channel(): + synth = Yamaha77Voice("TG77", "SP|Cosmo") + device = 5 + preset = knobkraft.load_sysex(str(FIXTURES / TG77_PRESET_ONE))[0] + match = _with_memory(preset, device, 2, 0) + synth.createDeviceDetectMessage(device) + assert synth.channelIfValidDeviceResponse(match) == device + assert synth.channelIfValidDeviceResponse(_system_reply(device, 8)) == -1 + + synth.createDeviceDetectMessage(device) + assert synth.channelIfValidDeviceResponse(_system_reply(device, 3)) == -1 + assert synth.createCustomProgramChange(device, 17) == [0xC8, 17] + assert synth.channelIfValidDeviceResponse(match) == device + assert synth.createCustomProgramChange(device, 17) == [0xC3, 17] + + +@pytest.mark.parametrize("program,bank_selector", [(0, 122), (64, 124), (191, 117)]) +def test_sy77_direct_mode_selects_voice_bank_then_slot(program, bank_selector): + assert sy77.createCustomProgramChange(4, program) == [ + 0xC4, bank_selector, 0xC4, program % 64, + ] + + +def test_tg77_normal_mode_uses_the_selected_internal_bank(): + assert tg77.createCustomProgramChange(4, 63) == [0xC4, 63] + assert tg77.createCustomProgramChange(4, 64) == [] + + +@pytest.mark.parametrize("module", [sy77, tg77]) +@pytest.mark.parametrize("program", [-1, 192]) +def test_invalid_program_never_becomes_wire_data(module, program): + assert module.createCustomProgramChange(3, program) == [] + assert module.createProgramDumpRequest(3, program) == [] + + +@pytest.mark.parametrize("module", [sy77, tg77]) +def test_preset_bank_reads_and_writes_are_distinct(module): + assert [desc["isROM"] for desc in module.bankDescriptors()] == [False, True, True] + for program, address in ((0, [0, 0]), (63, [0, 63]), (64, [2, 0]), (127, [2, 63]), + (128, [3, 0]), (191, [3, 63])): + request = module.createProgramDumpRequest(5, program) + assert request[2] == 0x25 + assert request[-3:-1] == address + + preset = knobkraft.load_sysex(str(FIXTURES / TG77_PRESET_ONE))[0] + assert module.convertToProgramDump(7, preset, 64) == [] + assert module.numberFromDump(module.convertToProgramDump(7, preset, 15)) == 15 + assert not hasattr(module, "convertPatchesToBankDump") + + +@pytest.mark.parametrize("module", [sy77, tg77]) +def test_large_voices_require_an_explicit_bank_d_slot(module): + voices = knobkraft.load_sysex(str(FIXTURES / TG77_INTERNAL)) + for index in (66, 71, 73, 74): + voice = voices[index] + assert module.convertToProgramDump(5, voice, 47) == [] + converted = module.convertToProgramDump(5, voice, 48) + assert module.numberFromDump(converted) == 48 + assert converted[2] == 5 + assert module.calculateFingerprint(voice) == module.calculateFingerprint(converted) + + +def test_model_specific_edit_buffer_requests(): + dump = [0xF0, 0x43, 0x26, 0x7A, *b"LM 8101VC", *([0] * 14), 0x7F, 0, 0xF7] + assert knobkraft.splitSysex(sy77.createEditBufferRequest(6)) == [dump] + assert knobkraft.splitSysex(tg77.createEditBufferRequest(6)) == [ + [0xF0, 0x43, 0x16, 0x34, 0x0D, 0, 0, 5, 0, 0x7F, 0xF7], + dump, + [0xF0, 0x43, 0x16, 0x34, 0x0D, 0, 0, 0, 0, 0x7F, 0xF7], + ] + assert tg77.generalMessageDelay() == 800 + + +def test_tg77_front_panel_single_voice_preserves_the_reported_slot(): + voice = knobkraft.load_sysex(str(FIXTURES / TG77_INTERNAL))[0] + manual = _with_memory(voice, 6, 0x7F, 0x2E) + assert tg77.numberFromDump(manual) == 0x2E + assert tg77.isSingleProgramDump(manual) + assert not tg77.isEditBufferDump(manual) + + # A01 has the same address as the edit buffer. + manual_a01 = _with_memory(voice, 6, 0x7F, 0) + assert tg77.isEditBufferDump(manual_a01) + assert not tg77.isSingleProgramDump(manual_a01) + + +def test_malformed_dumps_are_rejected_and_renames_preserve_sound(): + voices = knobkraft.load_sysex(str(FIXTURES / TG77_INTERNAL)) + voice = voices[0] + invalid_length = voice.copy() + invalid_length[5] ^= 1 + invalid_checksum = voice.copy() + invalid_checksum[-2] ^= 1 + for corrupt in (voice[:-1], invalid_length, invalid_checksum, _system_reply(0, 8)): + assert not tg77.isSingleProgramDump(corrupt) + assert not tg77.isEditBufferDump(corrupt) + assert tg77.convertToProgramDump(0, corrupt, 0) == [] + + renamed = tg77.renamePatch(voice, "Tést") + assert tg77.nameFromDump(renamed) == "T st" + assert tg77.isSingleProgramDump(renamed) + assert tg77.calculateFingerprint(renamed) == tg77.calculateFingerprint(voice) + assert tg77.calculateFingerprint(voices[19]) != tg77.calculateFingerprint(voice) diff --git a/adaptations/yamaha/Yamaha77Voice.py b/adaptations/yamaha/Yamaha77Voice.py new file mode 100644 index 00000000..346d68d0 --- /dev/null +++ b/adaptations/yamaha/Yamaha77Voice.py @@ -0,0 +1,297 @@ +"""Shared SY77/TG77 voice support by hmmbug and Giovanni Candiago.""" + +import hashlib + +YAMAHA = 0x43 +FORMAT = 0x7A +VOICE = b"LM 8101VC" +SYSTEM = b"LM 8101SY" + +INTERNAL, PRESET_1, PRESET_2, EDIT = 0x00, 0x02, 0x03, 0x7F +BANKS = (INTERNAL, PRESET_1, PRESET_2) +BANK_NAMES = ("Internal", "Preset 1", "Preset 2") +BANK_LABELS = ("IN", "P1", "P2") +VOICE_MODE_PROGRAM_CHANGES = (122, 124, 117) +BANK_SIZE = 64 +BANK_D_START = 48 +BANK_D_ONLY = {0x02: "4AFM mono", 0x07: "4AWM", 0x09: "2AFM+2AWM", 0x0A: "Drum Set"} + +MEMORY_TYPE = 30 +MEMORY_NUMBER = 31 +VOICE_TYPE = 32 +VOICE_NAME = slice(33, 43) +VOICE_RECEIVE_CHANNEL = 80 + + +def _device_number(channel): + return channel if channel is not None and 0 <= channel < 16 else 0 + + +def _checksum(data): + return (-sum(data)) & 0x7F + + +def _is_bulk_dump(message, identifier, minimum_size): + return ( + len(message) >= minimum_size + and message[0] == 0xF0 + and message[1] == YAMAHA + and 0 <= message[2] < 16 + and message[3] == FORMAT + and message[-1] == 0xF7 + and (message[4] << 7) + message[5] == len(message) - 8 + and all(0 <= byte < 0x80 for byte in message[1:-1]) + and bytes(message[6:16]) == identifier + and message[-2] == _checksum(message[6:-2]) + ) + + +def _voice_address(message): + if not _is_bulk_dump(message, VOICE, 45): + return None + memory, slot = message[MEMORY_TYPE:MEMORY_NUMBER + 1] + if memory == INTERNAL: + return memory, slot & 0x3F + if memory in (PRESET_1, PRESET_2, EDIT) and slot < BANK_SIZE: + return memory, slot + return None + + +def _dump_request(channel, identifier, memory=0, slot=0): + return [ + 0xF0, YAMAHA, 0x20 | _device_number(channel), FORMAT, + *identifier, *([0] * 14), memory, slot, 0xF7, + ] + + +def _with_address(channel, message, memory, slot): + result = list(message) + result[2] = _device_number(channel) + result[MEMORY_TYPE:MEMORY_NUMBER + 1] = [memory, slot] + result[-2] = _checksum(result[6:-2]) + return result + + +def bankDescriptors(): + return [ + {"bank": bank, "name": name, "size": BANK_SIZE, "type": "Voice", "isROM": bank != 0} + for bank, name in enumerate(BANK_NAMES) + ] + + +def friendlyBankName(bank): + return BANK_NAMES[bank] + + +def friendlyProgramName(program): + if not 0 <= program < BANK_SIZE * len(BANKS): + return "Edit voice" + bank, slot = divmod(program, BANK_SIZE) + group, position = divmod(slot, 16) + return f"{BANK_LABELS[bank]}-{'ABCD'[group]}{position + 1:02d}" + + +def createProgramDumpRequest(channel, program): + if not 0 <= program < BANK_SIZE * len(BANKS): + return [] + bank, slot = divmod(program, BANK_SIZE) + return _dump_request(channel, VOICE, BANKS[bank], slot) + + +def numberFromDump(message): + address = _voice_address(message) + if address is None or address == (EDIT, 0): + return -1 + memory, slot = address + # A TG77 front-panel single-voice dump can carry EDIT and its source slot. + return slot if memory == EDIT else BANKS.index(memory) * BANK_SIZE + slot + + +def isSingleProgramDump(message): + return numberFromDump(message) >= 0 + + +def isEditBufferDump(message): + return _voice_address(message) == (EDIT, 0) + + +def convertToEditBuffer(channel, message): + if _voice_address(message) is None: + return [] + return _with_address(channel, message, EDIT, 0) + + +def convertToProgramDump(channel, message, program): + if _voice_address(message) is None or not 0 <= program < BANK_SIZE: + print("Yamaha SY77/TG77: choose a valid voice and an internal slot from A01 to D16.") + return [] + + voice_type = message[VOICE_TYPE] + if voice_type in BANK_D_ONLY and program < BANK_D_START: + print(f"Yamaha SY77/TG77: {BANK_D_ONLY[voice_type]} cannot be stored at " + f"{friendlyProgramName(program)}. Choose an internal slot from D01 to D16.") + return [] + return _with_address(channel, message, INTERNAL, program) + + +def nameFromDump(message): + return "".join(chr(byte) if 32 <= byte <= 126 else " " for byte in message[VOICE_NAME]).strip() + + +def isDefaultName(patch_name): + return patch_name.strip().upper() in ("", "INIT VOICE") + + +def renamePatch(message, new_name): + if _voice_address(message) is None: + return list(message) + result = list(message) + result[VOICE_NAME] = [ + ord(character) if " " <= character <= "~" else 0x20 + for character in new_name[:10].ljust(10) + ] + result[-2] = _checksum(result[6:-2]) + return result + + +def calculateFingerprint(message): + # Ignore addressing, name, framing and checksum. Keep the voice type and + # effect mode along with the other sound parameters, as in Giovanni's PR. + return hashlib.md5(bytes(message[VOICE_TYPE:VOICE_TYPE + 1]) + bytes(message[43:-2])).hexdigest() + + +class Yamaha77Voice: + def __init__(self, model, first_preset_name): + self.model = model + self.first_preset_name = first_preset_name + self._probe_replies = {} + self._voice_channels = {} + + def name(self): + return f"Yamaha {self.model}" + + def setupHelp(self): + if self.model == "TG77": + program_change = ( + "For Program change send mode, use Normal mode with Internal selected in Voice Play. " + "Audition presets using the edit buffer." + ) + else: + program_change = "For Program change send mode, set Program Change to Direct." + return ( + f"This adaptation supports voices. {program_change} " + "Run detection again after changing the Voice Receive Channel. If the system reply is " + "unavailable, Program Change uses the SysEx device number's corresponding MIDI channel. " + "Turn Bulk Protect off on the instrument before writing to internal memory. " + "4AFM mono, 4AWM, 2AFM+2AWM and Drum Set voices require an internal slot from D01 to D16." + ) + + def needsChannelSpecificDetection(self): + return True + + def createDeviceDetectMessage(self, channel): + device = _device_number(channel) + self._probe_replies[device] = (False, None) + # The first factory preset identifies the model. The separate system + # reply provides the MIDI voice channel without changing any settings. + return _dump_request(device, VOICE, PRESET_1, 0) + _dump_request(device, SYSTEM) + + def channelIfValidDeviceResponse(self, message): + if _is_bulk_dump(message, SYSTEM, VOICE_RECEIVE_CHANNEL + 3): + device = message[2] + matched, _ = self._probe_replies.get(device, (False, None)) + voice_channel = message[VOICE_RECEIVE_CHANNEL] + voice_channel = voice_channel if voice_channel < 16 else device + self._probe_replies[device] = (matched, voice_channel) + if matched: + self._voice_channels[device] = voice_channel + return -1 + + if _voice_address(message) not in ((PRESET_1, 0), (EDIT, 0)): + return -1 + if nameFromDump(message) != self.first_preset_name: + return -1 + + device = message[2] + _, voice_channel = self._probe_replies.get(device, (False, None)) + self._probe_replies[device] = (True, voice_channel) + self._voice_channels[device] = device if voice_channel is None else voice_channel + return device + + def createEditBufferRequest(self, channel): + request = _dump_request(channel, VOICE, EDIT, 0) + if self.model == "SY77": + return request + + # The TG77 requires entering Edit before requesting its current voice. + device = 0x10 | _device_number(channel) + enter_edit = [0xF0, YAMAHA, device, 0x34, 0x0D, 0, 0, 5, 0, 0x7F, 0xF7] + enter_voice = [0xF0, YAMAHA, device, 0x34, 0x0D, 0, 0, 0, 0, 0x7F, 0xF7] + return enter_edit + request + enter_voice + + def createCustomProgramChange(self, channel, program): + if not 0 <= program < BANK_SIZE * len(BANKS): + return [] + device = _device_number(channel) + status = 0xC0 | self._voice_channels.get(device, device) + bank, slot = divmod(program, BANK_SIZE) + if self.model == "SY77": + # Yamaha's Direct mode uses PC 124 for Voice Preset 1. + return [status, VOICE_MODE_PROGRAM_CHANGES[bank], status, slot] + if bank == 0: + return [status, slot] + print("Yamaha TG77: use edit-buffer send mode to audition preset voices.") + return [] + + def install(self, namespace): + for name in ( + "name", "setupHelp", "needsChannelSpecificDetection", + "createDeviceDetectMessage", "channelIfValidDeviceResponse", + "createEditBufferRequest", "createCustomProgramChange", + ): + namespace[name] = getattr(self, name) + + for function in ( + bankDescriptors, friendlyBankName, friendlyProgramName, + createProgramDumpRequest, numberFromDump, isSingleProgramDump, + isEditBufferDump, convertToEditBuffer, convertToProgramDump, + nameFromDump, isDefaultName, renamePatch, calculateFingerprint, + ): + namespace[function.__name__] = function + namespace["isPartOfSingleProgramDump"] = isSingleProgramDump + + +def voice_test_data(fixture, count, samples, mode_samples=()): + """Build generic tests from captures of internal voices.""" + import testing + + def programs(data): + regular_voices = [ + (index, index, name, label) for index, name, label in samples + ] + # Giovanni placed the 11 additional modes at D01 to D11. + mode_voices = [ + (fixture_index, 48 + mode, name, f"IN-D{mode + 1:02d}") + for mode, (fixture_index, name) in enumerate(mode_samples) + ] + return [ + testing.ProgramTestData( + message=data.all_messages[index], number=slot, name=name, + friendly_number=label, rename_name="New Patch", target_no=slot, + ) + for index, slot, name, label in regular_voices + mode_voices + ] + + def edit_buffers(data): + return [ + testing.ProgramTestData( + message=convertToEditBuffer(0, program.message.byte_list), + name=program.name, rename_name=program.rename_name, target_no=program.target_no, + ) + for program in programs(data) + ] + + return testing.TestData( + sysex=fixture, expected_patch_count=count, program_generator=programs, + edit_buffer_generator=edit_buffers, friendly_bank_name=(0, "Internal"), + ) diff --git a/adaptations/yamaha/__init__.py b/adaptations/yamaha/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/data/supported-synths.json b/data/supported-synths.json index 3177bc2b..74c2aa2b 100644 --- a/data/supported-synths.json +++ b/data/supported-synths.json @@ -1,7 +1,7 @@ { "source_revision": "76b39b7c767129eaeb01534008547e8a320b0886", "release_checked": "2.10.2", - "count": 92, + "count": 94, "synths": [ { "manufacturer": "Access", @@ -795,6 +795,24 @@ "kudos": "Thanks to @milnak!", "availability": "2.10.2" }, + { + "manufacturer": "Yamaha", + "synth": "SY77 (voices)", + "status": "beta", + "statusLabel": "Beta", + "type": "adaptation", + "kudos": "Contributed by @hmmbug and Giovanni Candiago. Original SY77 hardware testing by @hmmbug.", + "availability": "After 2.10.2" + }, + { + "manufacturer": "Yamaha", + "synth": "TG77 (voices)", + "status": "beta", + "statusLabel": "Beta", + "type": "adaptation", + "kudos": "Contributed by @hmmbug and Giovanni Candiago. Original TG77 hardware testing by Giovanni Candiago.", + "availability": "After 2.10.2" + }, { "manufacturer": "Yamaha", "synth": "TX7", diff --git a/docs/data/supported-synths.yml b/docs/data/supported-synths.yml index 345c380b..95bf3ad0 100644 --- a/docs/data/supported-synths.yml +++ b/docs/data/supported-synths.yml @@ -531,6 +531,18 @@ synths: type: adaptation kudos: Thanks to @milnak! availability: 2.10.2 +- manufacturer: Yamaha + synth: SY77 (voices) + status: beta + type: adaptation + kudos: Contributed by @hmmbug and Giovanni Candiago. Original SY77 hardware testing by @hmmbug. + availability: After 2.10.2 +- manufacturer: Yamaha + synth: TG77 (voices) + status: beta + type: adaptation + kudos: Contributed by @hmmbug and Giovanni Candiago. Original TG77 hardware testing by Giovanni Candiago. + availability: After 2.10.2 - manufacturer: Yamaha synth: TX7 status: works diff --git a/docs/supported-synths.md b/docs/supported-synths.md index 2a2555e3..1649908b 100644 --- a/docs/supported-synths.md +++ b/docs/supported-synths.md @@ -287,6 +287,8 @@ Use the searchable model filter, or choose a manufa | FS1R | alpha | adaptation | 2.10.2 | Thanks to @markusschlosser for testing! | | reface DX | works | adaptation | 2.10.2 | | | reface CP | beta | adaptation | 2.10.2 | Thanks to @milnak! | +| SY77 (voices) | beta | adaptation | After 2.10.2 | Contributed by @hmmbug and Giovanni Candiago. Original SY77 hardware testing by @hmmbug. | +| TG77 (voices) | beta | adaptation | After 2.10.2 | Contributed by @hmmbug and Giovanni Candiago. Original TG77 hardware testing by Giovanni Candiago. | | TX7 | works | adaptation | 2.10.2 | Thanks to Gerome S! | | TX81Z | works | adaptation | 2.10.2 | Contributed by @summersetter! | | Yamaha YC61/YC73/YC88 | works | adaptation | 2.10.2 | Thanks to @milnak! | diff --git a/docs/yamaha-sy77-tg77.md b/docs/yamaha-sy77-tg77.md new file mode 100644 index 00000000..6d6f77bf --- /dev/null +++ b/docs/yamaha-sy77-tg77.md @@ -0,0 +1,28 @@ +# Yamaha SY77 and TG77 voice support + +The two adaptations share the Yamaha voice SysEx format. Both expose 64 writable Internal slots and two read-only 64-voice preset banks. The TG77 uses a timed Edit → Dump → Voice sequence to read the edit buffer. The SY77 sends the edit-buffer request directly. + +For SY77 Program change send mode, set Program Change to Direct. The app sends the voice-bank selector followed by the slot. For TG77 Program change send mode, set Program Change to Normal and select Internal in Voice Play before auditioning internal patches. Use edit-buffer send mode to audition TG77 presets. Program Change uses the Voice Receive Channel from the System dump, with the SysEx device number as a fallback. Run detection again after changing these settings. + +Detection requests the first factory preset and the System dump so it can identify the model and read the MIDI channel without changing Bulk Protect. The app also accepts the TG77's front-panel voice dumps. A front-panel dump of A01 carries the same address as an edit-buffer dump and is classified as an edit-buffer voice. + +Turn Bulk Protect off on the instrument before writing to internal memory. 4AFM mono, 4AWM, 2AFM+2AWM, and Drum Set voices require a slot in D01–D16. The adaptation rejects an incompatible destination. The dedicated bank-dump writer is deferred. The app can still send a bank as individual slot writes, so an incompatible slot can stop a transfer after earlier valid slots have been written. + +## Contributors and hardware evidence + +| Contributor | Hardware evidence from the original contributions | +| --- | --- | +| [@hmmbug](https://github.com/hmmbug) | Wrote the original SY77 and TG77 adaptations, supplied their bank mapping and three fixtures, and reported several weeks of stable use of the SY77 adaptation on an SY77 with ROM 1.5. See [PR #551](https://github.com/christofmuc/KnobKraft-orm/pull/551) and the [SY77 hardware report](https://github.com/christofmuc/KnobKraft-orm/pull/551#issuecomment-4946532875). | +| Giovanni Candiago | Wrote the TG77-tested adaptation and supplied a fixture with 64 internal voices and all 11 voice modes. On a TG77 he verified detection with the original System-dump probe, edit-buffer retrieval including the largest voice and send to the edit buffer, reads of all 64 internal voices, front-panel single and full-memory dumps, and Normal-mode Program Change with SysEx device number 1 and Voice Receive Channel 9. See [PR #597](https://github.com/christofmuc/KnobKraft-orm/pull/597). | + +These reports cover the contributors' original versions. The combined version still needs retesting on both instruments. + +## Combined-version retest + +- On each model, run detection with different SysEx and voice channels. Confirm the model is identified, the program change arrives on the voice channel, and Bulk Protect retains its initial setting. When both units are available, check that only the matching adaptation detects each unit. +- On each model, read Internal and both preset banks. Retrieve a 4AFM mono edit-buffer voice and send a voice back to the edit buffer. On TG77, confirm the front panel returns to Voice Play and verify both a single front-panel dump and a full 64-voice dump. +- On SY77, in Direct mode, audition an internal voice and a voice from each preset bank. Start in Multi mode for the Preset 1 check and verify that the synth switches to the correct Voice bank. +- On TG77, in Normal mode, select Internal in Voice Play and audition an internal voice. Switch to edit-buffer send mode to audition a preset. +- Back up internal memory before testing a write. Test individual writes to scratch slots and read them back before attempting any bank transfer. Check that an incompatible write to A–C leaves the slot intact and that an explicit D-slot write works for the same voice. + +The bank selectors are documented in the [Yamaha SY77 operating manual](https://chrisarndt.de/files/yamaha/sy77/SY77%20-%20Operating%20Manual%20-%20Complete.pdf) and [Yamaha TG77 MIDI Data Format](https://manualzz.com/doc/1538269/yamaha-tg77-user-manual).