franta-hg@1
|
1 |
/**
|
franta-hg@1
|
2 |
* SysEx message encoder for Roland MT-32
|
franta-hg@1
|
3 |
* Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
|
franta-hg@1
|
4 |
*
|
franta-hg@1
|
5 |
* This program is free software: you can redistribute it and/or modify
|
franta-hg@1
|
6 |
* it under the terms of the GNU General Public License as published by
|
franta-hg@1
|
7 |
* the Free Software Foundation, version 3 of the License.
|
franta-hg@1
|
8 |
*
|
franta-hg@1
|
9 |
* This program is distributed in the hope that it will be useful,
|
franta-hg@1
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
franta-hg@1
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
franta-hg@1
|
12 |
* GNU General Public License for more details.
|
franta-hg@1
|
13 |
*
|
franta-hg@1
|
14 |
* You should have received a copy of the GNU General Public License
|
franta-hg@1
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
franta-hg@1
|
16 |
*/
|
franta-hg@0
|
17 |
#include <iostream>
|
franta-hg@0
|
18 |
#include <iomanip>
|
franta-hg@0
|
19 |
|
franta-hg@0
|
20 |
/**
|
franta-hg@0
|
21 |
* Translates text from standard input to a hex-formatted System Exclusive (SysEx) message for Roland MT-32,
|
franta-hg@0
|
22 |
* which instructs the unit to show given text on the display.
|
franta-hg@0
|
23 |
*
|
franta-hg@0
|
24 |
* Roland MT-32 is capable to display 20 characters.
|
franta-hg@0
|
25 |
* Longer messages are silently truncated by the MT-32 unit (this software does not check the length).
|
franta-hg@0
|
26 |
*
|
franta-hg@0
|
27 |
* The SysEx message contains a checksum.
|
franta-hg@0
|
28 |
* If the checksum is wrong, the MT-32 unit shows the "Exc. Checksum error" message for few seconds
|
franta-hg@0
|
29 |
* and then returns back to the default screen.
|
franta-hg@0
|
30 |
*
|
franta-hg@2
|
31 |
* Only printable ASCII characters are supported. Other characters (bytes) are replaced by "."
|
franta-hg@2
|
32 |
*
|
franta-hg@2
|
33 |
* Some characters are displayed differently:
|
franta-hg@2
|
34 |
* ASCII MT-32
|
franta-hg@2
|
35 |
* ~ →
|
franta-hg@2
|
36 |
* \ ¥
|
franta-hg@2
|
37 |
*
|
franta-hg@2
|
38 |
* Usage examples:
|
franta-hg@0
|
39 |
* amidi --port="hw:2,0,0" --send-hex="$(echo -n ' Run GNU/Linux ' | ./mt-32-display )"
|
franta-hg@2
|
40 |
* while read message; do amidi --port="hw:2,0,0" --send-hex="$(echo -n "$message" | ./mt-32-display )"; done
|
franta-hg@0
|
41 |
*
|
franta-hg@0
|
42 |
* @param argc
|
franta-hg@0
|
43 |
* @param argv
|
franta-hg@0
|
44 |
* @return
|
franta-hg@0
|
45 |
*/
|
franta-hg@0
|
46 |
int main(int argc, char**argv) {
|
franta-hg@0
|
47 |
std::cout << "f0 41 10 16 12 20 00 00 ";
|
franta-hg@3
|
48 |
// f0 = start of SysEx message
|
franta-hg@3
|
49 |
// 41 = Roland manufacturer ID, see https://www.midi.org/specifications-old/item/manufacturer-id-numbers
|
franta-hg@3
|
50 |
// 10 = device ID
|
franta-hg@3
|
51 |
// 16 = model ID
|
franta-hg@3
|
52 |
// 12 = command ID
|
franta-hg@3
|
53 |
// 20 00 00 = show message on the display
|
franta-hg@3
|
54 |
|
franta-hg@3
|
55 |
// The start and end of the SysEx message and the manufacturer ID are part of the MIDI standard.
|
franta-hg@3
|
56 |
// The rest of the bytes is Roland specific.
|
franta-hg@3
|
57 |
|
franta-hg@3
|
58 |
// TODO: allow changing device ID to support controlling multiple devices in daisy-chain
|
franta-hg@3
|
59 |
// TODO: allow custom replacement character ('.')
|
franta-hg@3
|
60 |
|
franta-hg@0
|
61 |
std::cout << std::hex << std::setfill('0');
|
franta-hg@0
|
62 |
|
franta-hg@0
|
63 |
int sum = 0;
|
franta-hg@0
|
64 |
|
franta-hg@0
|
65 |
// 20 00 00 = display message
|
franta-hg@0
|
66 |
sum += 0x20;
|
franta-hg@0
|
67 |
sum += 0x00;
|
franta-hg@0
|
68 |
sum += 0x00;
|
franta-hg@0
|
69 |
|
franta-hg@0
|
70 |
for (char ch; std::cin.read(&ch, 1).good();) {
|
franta-hg@2
|
71 |
if (ch < 32 || ch > 126) ch = '.';
|
franta-hg@0
|
72 |
std::cout << std::setw(2) << ((int) ch) << " ";
|
franta-hg@0
|
73 |
sum += ch;
|
franta-hg@0
|
74 |
}
|
franta-hg@0
|
75 |
|
franta-hg@0
|
76 |
sum %= 128;
|
franta-hg@0
|
77 |
sum = 128 - sum;
|
franta-hg@0
|
78 |
std::cout << std::setw(2) << sum;
|
franta-hg@3
|
79 |
|
franta-hg@0
|
80 |
std::cout << " f7";
|
franta-hg@3
|
81 |
// f7 = end of SysEx message
|
franta-hg@0
|
82 |
|
franta-hg@0
|
83 |
std::cout << std::endl;
|
franta-hg@0
|
84 |
return 0;
|
franta-hg@0
|
85 |
}
|