franta-hg@1: /** franta-hg@1: * SysEx message encoder for Roland MT-32 franta-hg@1: * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) franta-hg@1: * franta-hg@1: * This program is free software: you can redistribute it and/or modify franta-hg@1: * it under the terms of the GNU General Public License as published by franta-hg@1: * the Free Software Foundation, version 3 of the License. franta-hg@1: * franta-hg@1: * This program is distributed in the hope that it will be useful, franta-hg@1: * but WITHOUT ANY WARRANTY; without even the implied warranty of franta-hg@1: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the franta-hg@1: * GNU General Public License for more details. franta-hg@1: * franta-hg@1: * You should have received a copy of the GNU General Public License franta-hg@1: * along with this program. If not, see . franta-hg@1: */ franta-hg@0: #include franta-hg@0: #include franta-hg@0: franta-hg@0: /** franta-hg@0: * Translates text from standard input to a hex-formatted System Exclusive (SysEx) message for Roland MT-32, franta-hg@0: * which instructs the unit to show given text on the display. franta-hg@0: * franta-hg@0: * Roland MT-32 is capable to display 20 characters. franta-hg@0: * Longer messages are silently truncated by the MT-32 unit (this software does not check the length). franta-hg@0: * franta-hg@0: * The SysEx message contains a checksum. franta-hg@0: * If the checksum is wrong, the MT-32 unit shows the "Exc. Checksum error" message for few seconds franta-hg@0: * and then returns back to the default screen. franta-hg@0: * franta-hg@2: * Only printable ASCII characters are supported. Other characters (bytes) are replaced by "." franta-hg@2: * franta-hg@2: * Some characters are displayed differently: franta-hg@2: * ASCII MT-32 franta-hg@2: * ~ → franta-hg@2: * \ ¥ franta-hg@2: * franta-hg@2: * Usage examples: franta-hg@0: * amidi --port="hw:2,0,0" --send-hex="$(echo -n ' Run GNU/Linux ' | ./mt-32-display )" franta-hg@2: * while read message; do amidi --port="hw:2,0,0" --send-hex="$(echo -n "$message" | ./mt-32-display )"; done franta-hg@0: * franta-hg@0: * @param argc franta-hg@0: * @param argv franta-hg@0: * @return franta-hg@0: */ franta-hg@0: int main(int argc, char**argv) { franta-hg@0: std::cout << "f0 41 10 16 12 20 00 00 "; franta-hg@0: std::cout << std::hex << std::setfill('0'); franta-hg@0: franta-hg@0: int sum = 0; franta-hg@0: franta-hg@0: // 20 00 00 = display message franta-hg@0: sum += 0x20; franta-hg@0: sum += 0x00; franta-hg@0: sum += 0x00; franta-hg@0: franta-hg@0: for (char ch; std::cin.read(&ch, 1).good();) { franta-hg@2: if (ch < 32 || ch > 126) ch = '.'; franta-hg@0: std::cout << std::setw(2) << ((int) ch) << " "; franta-hg@0: sum += ch; franta-hg@0: } franta-hg@0: franta-hg@0: sum %= 128; franta-hg@0: sum = 128 - sum; franta-hg@0: std::cout << std::setw(2) << sum; franta-hg@0: std::cout << " f7"; franta-hg@0: franta-hg@0: std::cout << std::endl; franta-hg@0: return 0; franta-hg@0: }