author | František Kučera <franta-hg@frantovo.cz> |
Wed, 20 May 2020 23:39:01 +0200 | |
branch | v_0 |
changeset 4 | dfd422ad13d3 |
parent 3 | 51a8362261a9 |
permissions | -rw-r--r-- |
1 | 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 |
*/ |
|
0 | 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 |
* |
|
2
a84830179027
filter ASCII characters
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
31 |
* Only printable ASCII characters are supported. Other characters (bytes) are replaced by "." |
a84830179027
filter ASCII characters
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
32 |
* |
a84830179027
filter ASCII characters
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
33 |
* Some characters are displayed differently: |
a84830179027
filter ASCII characters
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
34 |
* ASCII MT-32 |
a84830179027
filter ASCII characters
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
35 |
* ~ → |
a84830179027
filter ASCII characters
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
36 |
* \ ¥ |
a84830179027
filter ASCII characters
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
37 |
* |
a84830179027
filter ASCII characters
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
38 |
* Usage examples: |
0 | 39 |
* amidi --port="hw:2,0,0" --send-hex="$(echo -n ' Run GNU/Linux ' | ./mt-32-display )" |
2
a84830179027
filter ASCII characters
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
40 |
* while read message; do amidi --port="hw:2,0,0" --send-hex="$(echo -n "$message" | ./mt-32-display )"; done |
0 | 41 |
* |
42 |
* @param argc |
|
43 |
* @param argv |
|
44 |
* @return |
|
45 |
*/ |
|
46 |
int main(int argc, char**argv) { |
|
47 |
std::cout << "f0 41 10 16 12 20 00 00 "; |
|
3 | 48 |
// f0 = start of SysEx message |
49 |
// 41 = Roland manufacturer ID, see https://www.midi.org/specifications-old/item/manufacturer-id-numbers |
|
50 |
// 10 = device ID |
|
51 |
// 16 = model ID |
|
52 |
// 12 = command ID |
|
53 |
// 20 00 00 = show message on the display |
|
54 |
||
55 |
// The start and end of the SysEx message and the manufacturer ID are part of the MIDI standard. |
|
56 |
// The rest of the bytes is Roland specific. |
|
57 |
||
58 |
// TODO: allow changing device ID to support controlling multiple devices in daisy-chain |
|
59 |
// TODO: allow custom replacement character ('.') |
|
60 |
||
0 | 61 |
std::cout << std::hex << std::setfill('0'); |
62 |
||
63 |
int sum = 0; |
|
64 |
||
65 |
// 20 00 00 = display message |
|
66 |
sum += 0x20; |
|
67 |
sum += 0x00; |
|
68 |
sum += 0x00; |
|
69 |
||
70 |
for (char ch; std::cin.read(&ch, 1).good();) { |
|
2
a84830179027
filter ASCII characters
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
71 |
if (ch < 32 || ch > 126) ch = '.'; |
0 | 72 |
std::cout << std::setw(2) << ((int) ch) << " "; |
73 |
sum += ch; |
|
74 |
} |
|
75 |
||
76 |
sum %= 128; |
|
77 |
sum = 128 - sum; |
|
78 |
std::cout << std::setw(2) << sum; |
|
3 | 79 |
|
0 | 80 |
std::cout << " f7"; |
3 | 81 |
// f7 = end of SysEx message |
0 | 82 |
|
83 |
std::cout << std::endl; |
|
84 |
return 0; |
|
85 |
} |