mt-32-display.cpp
author František Kučera <franta-hg@frantovo.cz>
Tue, 19 May 2020 16:03:25 +0200
branchv_0
changeset 1 6733bd832b61
parent 0 a7af46af7903
child 2 a84830179027
permissions -rw-r--r--
license: GNU GPLv3
     1 /**
     2  * SysEx message encoder for Roland MT-32
     3  * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
     4  *
     5  * This program is free software: you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation, version 3 of the License.
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    16  */
    17 #include <iostream>
    18 #include <iomanip>
    19 
    20 /**
    21  * Translates text from standard input to a hex-formatted System Exclusive (SysEx) message for Roland MT-32,
    22  * which instructs the unit to show given text on the display.
    23  * 
    24  * Roland MT-32 is capable to display 20 characters.
    25  * Longer messages are silently truncated by the MT-32 unit (this software does not check the length).
    26  * 
    27  * The SysEx message contains a checksum.
    28  * If the checksum is wrong, the MT-32 unit shows the "Exc. Checksum error" message for few seconds
    29  * and then returns back to the default screen.
    30  * 
    31  * Usage:
    32  *     amidi --port="hw:2,0,0" --send-hex="$(echo -n '   Run GNU/Linux    ' | ./mt-32-display )"
    33  * 
    34  * @param argc
    35  * @param argv
    36  * @return 
    37  */
    38 int main(int argc, char**argv) {
    39 	std::cout << "f0 41 10 16 12 20 00 00 ";
    40 	std::cout << std::hex << std::setfill('0');
    41 
    42 	int sum = 0;
    43 
    44 	// 20 00 00 = display message
    45 	sum += 0x20;
    46 	sum += 0x00;
    47 	sum += 0x00;
    48 
    49 	for (char ch; std::cin.read(&ch, 1).good();) {
    50 		std::cout << std::setw(2) << ((int) ch) << " ";
    51 		sum += ch;
    52 	}
    53 
    54 	sum %= 128;
    55 	sum = 128 - sum;
    56 	std::cout << std::setw(2) << sum;
    57 	std::cout << " f7";
    58 
    59 	std::cout << std::endl;
    60 	return 0;
    61 }