Receiving Midi Time Code Events
See original GitHub issueHi,
I’m new to C# and trying to figure out how the Midi Time Code works.
I use _inputDevice.EventReceived
and _inputDevice.MidiTimeCodeReceived
EventHandler to receive Full/Quarter Frame MTC events.
When I try to use them together, only _inputDevice.EventReceived
works.
Sorry for the stupid question, but why is _inputDevice.MidiTimeCodeReceived
not working in this case?
_inputDevice.MidiTimeCodeReceived += OnMidiTimeCodeReceived; // MTC Quarter Frame Event
_inputDevice.EventReceived += OnEventReceived; // MTC SysEx Full Frame Event
Input device is listening for events. Press any key to exit… 01/03/2021 16:04:12 MTC SysEx Full Frame: [1:53:11:13] 01/03/2021 16:04:12 MTC SysEx Full Frame: [1:2:44:24]
Separately each EventHandler works great
_inputDevice.MidiTimeCodeReceived += OnMidiTimeCodeReceived; // MTC Quarter Frame Event
// _inputDevice.EventReceived += OnEventReceived; // MTC SysEx Full Frame Event
Input device is listening for events. Press any key to exit… 01/03/2021 16:11:49 MTC Quarter Frame: [0:29:13:27] 01/03/2021 16:11:49 MTC Quarter Frame: [0:29:13:29]
// _inputDevice.MidiTimeCodeReceived += OnMidiTimeCodeReceived; // MTC Quarter Frame Event
_inputDevice.EventReceived += OnEventReceived; // MTC SysEx Full Frame Event
Input device is listening for events. Press any key to exit… 01/03/2021 16:31:14 MTC SysEx Full Frame: [0:17:13:14] 01/03/2021 16:31:14 MTC SysEx Full Frame: [1:18:44:21]
using System;
using Melanchall.DryWetMidi.Devices;
using Melanchall.DryWetMidi.Core;
namespace TimeCodeGen
{
class Program
{
private static InputDevice _inputDevice;
static void Main(string[] args)
{
_inputDevice = InputDevice.GetByName("testport");
_inputDevice.RaiseMidiTimeCodeReceived = true;
_inputDevice.MidiTimeCodeReceived += OnMidiTimeCodeReceived; // MTC Quarter Frame Event
_inputDevice.EventReceived += OnEventReceived; // MTC SysEx Full Frame Event
_inputDevice.StartEventsListening();
Console.WriteLine("Input device is listening for events. Press any key to exit...");
Console.ReadKey();
if (_inputDevice != null) { }
_inputDevice.Dispose();
}
// MTC SysEx Full Frame Event
private static void OnEventReceived(object sender, MidiEventReceivedEventArgs e)
{
int ffHours, ffMinutes, ffSeconds, ffFrames;
var sysEvent = e.Event as NormalSysExEvent;
byte[] sysData = sysEvent.Data;
ffHours = sysData[4] - 96;
ffMinutes = sysData[5];
ffSeconds = sysData[6];
ffFrames = sysData[7];
Console.WriteLine(DateTime.Now + " MTC SysEx Full Frame: [" + ffHours + ":" + ffMinutes + ":" + ffSeconds + ":" + ffFrames + "]");
}
// MTC Quarter Frame Event
private static void OnMidiTimeCodeReceived(object sender, MidiTimeCodeReceivedEventArgs tc)
{
Console.WriteLine(DateTime.Now + " MTC Quarter Frame: [" + tc.Hours + ":" + tc.Minutes + ":" + tc.Seconds + ":" + tc.Frames + "]");
}
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
I’m sure that shown events are not the same as you got when you opened the issue. In your code you have the line:
But in your log there are a lot of events that are not
NormalSysExEvent
so your program will crash onsysEvent.Data
. Use this code:So please uncomment
and check again.
@melanchall Thank you very much! It’s worked 😃