|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import serial |
| 4 | +import random |
| 5 | +import time |
| 6 | + |
| 7 | +#random.randint(0, 255) |
| 8 | + |
| 9 | +# Testing with `socat` |
| 10 | +s = serial.Serial('/dev/pts/8', 31250, timeout=0.1) |
| 11 | + |
| 12 | +# noteon = b'\x80\x18\x00' |
| 13 | +# noteoff = b'\x90\x18\x64' |
| 14 | +# polyphonickeypressure = None |
| 15 | +# controlchange = None |
| 16 | +# programchange = None |
| 17 | + |
| 18 | +noteon = bytes([ |
| 19 | + int('10000000', 2), |
| 20 | + int('00000001', 2), |
| 21 | + int('00000001', 2) |
| 22 | +]) |
| 23 | + |
| 24 | +noteoff = bytes([ |
| 25 | + int('10010000', 2), |
| 26 | + int('00000001', 2), |
| 27 | + int('00000001', 2) |
| 28 | +]) |
| 29 | + |
| 30 | +poly = bytes([ |
| 31 | + int('10100000', 2), |
| 32 | + int('00000001', 2), |
| 33 | + int('00000001', 2) |
| 34 | +]) |
| 35 | + |
| 36 | +controlchange = bytes([ |
| 37 | + int('10110000', 2), |
| 38 | + int('00000001', 2), |
| 39 | + int('00000001', 2) |
| 40 | +]) |
| 41 | + |
| 42 | +programchange = bytes([ |
| 43 | + int('11000000', 2), |
| 44 | + int('00000001', 2) |
| 45 | +]) |
| 46 | + |
| 47 | +channelpressure = bytes([ |
| 48 | + int('11010000', 2), |
| 49 | + int('00000001', 2) |
| 50 | +]) |
| 51 | + |
| 52 | +pitchbend = bytes([ |
| 53 | + int('11100000', 2), |
| 54 | + int('00000001', 2), |
| 55 | + int('00000001', 2) |
| 56 | +]) |
| 57 | + |
| 58 | +# same as control change? Yes, special controller numbers. |
| 59 | +channelmodemessage = bytes([ |
| 60 | + int('10110000', 2), |
| 61 | + 120, |
| 62 | + 0 |
| 63 | +]) |
| 64 | + |
| 65 | +sysex_begin = bytes([ |
| 66 | + int('11110000', 2), |
| 67 | + int('01111111', 2), |
| 68 | + int('01111111', 2) |
| 69 | +]) |
| 70 | +sysex_end = bytes([ |
| 71 | + int('11110111', 2) |
| 72 | +]) |
| 73 | + |
| 74 | +timecode_quarter_frame = bytes([ |
| 75 | + int('11110001', 2), |
| 76 | + int('01110001', 2) |
| 77 | +]) |
| 78 | + |
| 79 | +song_position_pointer = bytes([ |
| 80 | + int('11110010', 2), |
| 81 | + int('01110010', 2), |
| 82 | + int('01110010', 2) |
| 83 | +]) |
| 84 | + |
| 85 | +song_select = bytes([ |
| 86 | + int('11110011', 2), |
| 87 | + int('01110010', 2) |
| 88 | +]) |
| 89 | + |
| 90 | +time_clock = bytes([ |
| 91 | + int('11111000', 2) |
| 92 | +]) |
| 93 | + |
| 94 | +time_start = bytes([ |
| 95 | + int('11111010', 2) |
| 96 | +]) |
| 97 | + |
| 98 | +time_continue = bytes([ |
| 99 | + int('11111011', 2) |
| 100 | +]) |
| 101 | + |
| 102 | +time_stop = bytes([ |
| 103 | + int('11111100', 2) |
| 104 | +]) |
| 105 | + |
| 106 | +active_sensing = bytes([ |
| 107 | + int('11111110', 2) |
| 108 | +]) |
| 109 | + |
| 110 | +reset = bytes([ |
| 111 | + int('11111111', 2) |
| 112 | +]) |
| 113 | + |
| 114 | +# s.write(noteon) |
| 115 | +# s.write(noteoff) |
| 116 | +# s.write(poly) |
| 117 | +# s.write(controlchange) |
| 118 | + |
| 119 | +# s.write(programchange) |
| 120 | +# s.write(channelpressure) |
| 121 | +# s.write(pitchbend) |
| 122 | +# s.write(channelmodemessage) |
| 123 | + |
| 124 | +# s.write(timecode_quarter_frame) |
| 125 | +# s.write(song_position_pointer) |
| 126 | +# s.write(song_select) |
| 127 | +# s.write(time_clock) |
| 128 | + |
| 129 | +# s.write(time_start) |
| 130 | +# s.write(time_continue) |
| 131 | +# s.write(time_stop) |
| 132 | +# s.write(active_sensing) |
| 133 | + |
| 134 | +# s.write(reset) |
| 135 | + |
| 136 | +# s.write(sysex_begin) |
| 137 | +# s.write(sysex_end) |
| 138 | + |
| 139 | +bootmsg = [ 0xf0, 0x7f, 0x7f, 0x4, 0x1, 0x7f, 0x7f, 0xf7, 0xb0, 0x0, |
| 140 | + 0x0, 0xb0, 0x20, 0x0, 0xc0, 0x00, 0x02, 0x0b0, 0x4d, 0x40, |
| 141 | + 0xb0, 0x4c, 0x40, 0xb0, 0x46 , 0x40, 0xb0, 0xa, 0x40, |
| 142 | + 0xb0, 0x49, 0x40, 0xb0, 0x4b, 0x40, 0xb0, 0x48 , 0x40, |
| 143 | + 0xb0, 0x5b, 0xd, 0xb0, 0x5e, 0x0, 0xb0, 0x4a, 0x40, 0xb0, |
| 144 | + 0xa , 0x40, 0xb0, 0x65, 0x0, 0xb0, 0x64, 0x1, 0xb0, 0x6, |
| 145 | + 0x40, 0xb0, 0x26 , 0x0, 0xb0, 0x65, 0x7f, 0xb0, 0x64, |
| 146 | + 0x7f, 0xb0, 0x7, 0x7f, 0xb0, 0x65 , 0x0, 0xb0, 0x64, 0x0, |
| 147 | + 0xb0, 0x6, 0x2, 0xb0, 0x65, 0x7f, 0xb0, 0x64 , 0x7f, 0xb0, |
| 148 | + 0x5c, 0x0, 0xb0, 0x7, 0x7f, 0xb0, 0x1, 0x19, 0xb0, 0xb , |
| 149 | + 0x7f, 0x90, 0x47, 0x6a, 0x90, 0x48, 0x5a, 0x90, 0x47, 0x0, |
| 150 | + 0x90, 0x46 , 0x66, 0x90, 0x48, 0x0, 0x90, 0x44, 0x62, |
| 151 | + 0x90, 0x46, 0x0, 0x90, 0x46 , 0x52, 0x90, 0x44, 0x0, 0x90, |
| 152 | + 0x48, 0x44, 0x90, 0x44, 0x66, 0x90, 0x48 , 0x0, 0x90, |
| 153 | + 0x46, 0x0, 0x90, 0x41, 0x6a, 0x90, 0x44, 0x0, 0x90, 0x41 , |
| 154 | + 0x0, 0x90, 0x40, 0x6b, 0x90, 0x41, 0x44, 0x90, 0x40, 0x0, |
| 155 | + 0x90, 0x3f , 0x64, 0x90, 0x41, 0x0, 0x90, 0x3c, 0x59, |
| 156 | + 0x90, 0x3f, 0x0, 0x90, 0x3c , 0x0, 0x90, 0x3f, 0x61, 0x90, |
| 157 | + 0x3c, 0x63, 0x90, 0x3f, 0x0, 0x90, 0x3c , 0x0, 0x90, 0x3a, |
| 158 | + 0x66, 0x90, 0x38, 0x62, 0x90, 0x3a, 0x0, 0x90, 0x35 , |
| 159 | + 0x60, 0x90, 0x38, 0x0, 0x90, 0x33, 0x69, 0x90, 0x35, 0x0, |
| 160 | + 0x90, 0x33 , 0x0, 0x90, 0x30, 0x57, 0x90, 0x33, 0x4c, |
| 161 | + 0x90, 0x30, 0x0, 0x90, 0x33 , 0x0, 0x90, 0x34, 0x61, 0x90, |
| 162 | + 0x35, 0x43, 0x90, 0x34, 0x0, 0x90, 0x35 , 0x0, 0x90, 0x39, |
| 163 | + 0x31, 0x90, 0x39, 0x0, 0x90, 0x3c, 0x5f, 0x90, 0x3f , |
| 164 | + 0x60, 0x90, 0x3c, 0x0, 0x90, 0x3f, 0x0, 0x90, 0x41, 0x46, |
| 165 | + 0x90, 0x40 , 0x3a, 0x90, 0x40, 0x0, 0x90, 0x41, 0x0, 0x90, |
| 166 | + 0x44, 0x69, 0x90, 0x44, 0x0, 0x90, 0x41, 0x55, 0x90, 0x44, |
| 167 | + 0x6d, 0x90, 0x41, 0x0, 0x90, 0x46 , 0x52, 0x90, 0x44, 0x0, |
| 168 | + 0x90, 0x46, 0x0, 0x90, 0x48, 0x46, 0x90, 0x48 , 0x0, 0x90, |
| 169 | + 0x4b, 0x64, 0x90, 0x4b, 0x0, 0x90, 0x4c, 0x57, 0x90, 0x4d |
| 170 | + , 0x55, 0x90, 0x4c, 0x0, 0x90, 0x4b, 0x6c, 0x90, 0x4d, |
| 171 | + 0x0, 0x90, 0x4b , 0x0, 0x90, 0x48, 0x54, 0x90, 0x48, 0x0, |
| 172 | + 0x90, 0x4b, 0x67, 0x90, 0x4b , 0x0, 0x90, 0x48, 0x5e, |
| 173 | + 0x90, 0x48, 0x0, 0x90, 0x46, 0x5d, 0x90, 0x44 , 0x60, |
| 174 | + 0x90, 0x46, 0x0, 0x90, 0x44, 0x0, 0x90, 0x46, 0x46, 0x90, |
| 175 | + 0x44 , 0x5a, 0x90, 0x46, 0x0, 0x90, 0x41, 0x5d, 0x90, |
| 176 | + 0x44, 0x0, 0x90, 0x41 , 0x0 ] |
| 177 | + |
| 178 | +events = [ |
| 179 | + int('11110111', 2), |
| 180 | + int('11110110', 2), |
| 181 | + int('11110000', 2) |
| 182 | +] |
| 183 | + |
| 184 | +print("Bootmsg len {0}".format(len(bootmsg))) |
| 185 | +s.write(bytes(bootmsg)) |
| 186 | + |
| 187 | +# sleeptime = 32/48000 |
| 188 | +# for k in range(1, 100000000): |
| 189 | +# values = random.sample(list(range(0, 256)), 1) |
| 190 | + |
| 191 | +# time.sleep(sleeptime) |
| 192 | +# print("{0}, {1}".format(bytes(values), sleeptime)) |
| 193 | +# s.write(bytes(values)) |
| 194 | +# if sleeptime > 2/48000: |
| 195 | +# sleeptime /= 2 |
0 commit comments