• R/O
  • SSH
  • HTTPS

midisynth: Commit


Commit MetaInfo

Revision4 (tree)
Time2017-10-14 05:59:12
Authorjakobthomsen

Log Message

read channel nr

Change Summary

Incremental Difference

--- trunk/midisynth.cpp (revision 3)
+++ trunk/midisynth.cpp (revision 4)
@@ -122,7 +122,7 @@
122122 //if (inbyte != 254) // unsigned char: 254
123123 if(inbyte != -2) // signed char: -2
124124 {
125- std::cerr << "(received MIDI byte: " << (int)inbyte << "\n";
125+ std::cerr << "(received MIDI byte: " << (int)inbyte << ")\n";
126126 }
127127
128128 return (unsigned char)inbyte;
@@ -153,43 +153,61 @@
153153 unsigned char inbyte = GetByteWait();
154154
155155 // Received a command? If not, the previous stays active!
156- if(inbyte >= 128)
156+ //if(inbyte < 0) // for unsigned char
157+ if(inbyte >= 0x80) // 128
157158 {
158159 Cmd = inbyte;
159160 inbyte = GetByteWait();
160161 }
161162
162- if(Cmd == 144) // Currently we ONLY interpret NOTE-ON cmd.
163+ const int Channel = Cmd & 0xf;
164+ switch((Cmd >> 4) & 0xf)
163165 {
164- Key = inbyte;
166+ //case 0x8: // NOTE-OFF key velocity
167+ //{
168+ // // not implemented
169+ // break;
170+ //}
171+ case 0x9: // NOTE-ON key velocity
172+ {
173+ Key = inbyte;
165174
166- inbyte = GetByteWait();
175+ inbyte = GetByteWait();
167176
168- Vel = inbyte;
177+ Vel = inbyte;
169178
170- std::cerr << "received MIDI cmd NOTE-ON pitch: " << (int)Key << ", velocity: " << (int)Vel << "\n";
179+ std::cout << "received MIDI cmd NOTE-ON (channel: " << Channel << ") pitch: " << (int)Key << ", velocity: " << (int)Vel << "\n";
171180
172- if(Key >= 0 && Key < 127)
173- {
174- if(Vel > 0)
181+ if(Key >= 0 && Key < 127)
175182 {
176- data.params[Key].volume = (float)Vel / 255.0f; // Convert to volume [0..1] for playback.
177- data.params[Key].offset = data.sample_nr; // Store current time for fade-out.
183+ if(Vel > 0)
184+ {
185+ data.params[Key].volume = (float)Vel / 255.0f; // Convert to volume [0..1] for playback.
186+ data.params[Key].offset = data.sample_nr; // Store current time for fade-out.
187+ }
188+ else
189+ {
190+ data.params.erase(Key); // Erase instead of setting to zero to prevent stutter due to too many iterations
191+ }
178192 }
179193 else
180194 {
181- data.params.erase(Key); // Erase instead of setting to zero to prevent stutter due to too many iterations
195+ std::cerr << "Invalid key " << (int)Key << "\n";
182196 }
197+ break;
183198 }
184- else
199+ case 0xC: // patch-change instrument
185200 {
186- std::cerr << "Invalid key " << (int)Key << "\n";
201+ int Instrument = inbyte;
202+
203+ std::cerr << "instrument " << Instrument << " requested (channel: " << Channel << ")\n";
204+ break;
187205 }
206+ default:
207+ {
208+ std::cerr << "??? received MIDI byte: " << (int)inbyte << "\n";
209+ }
188210 }
189- else
190- {
191- std::cerr << "received MIDI bytes: " << (int)inbyte << "\n";
192- }
193211 }
194212 }
195213
Show on old repository browser