Skip to content

Commit f6e82d9

Browse files
committed
Decode MIDI messages in example
1 parent f5b5fea commit f6e82d9

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lighthouse-client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ tracing-subscriber = { version = "0.3", features = ["env-filter", "std"] }
3333
tokio = { version = "1.21", features = ["rt", "rt-multi-thread", "macros", "time"] }
3434
clap = { version = "4.5", features = ["derive", "env"] }
3535
dotenvy = "0.15"
36+
midi-msg = "0.8.0"

lighthouse-client/examples/midi_events.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use clap::Parser;
22
use futures::StreamExt;
33
use lighthouse_client::{protocol::Authentication, Lighthouse, Result, TokioWebSocket, LIGHTHOUSE_URL};
44
use lighthouse_protocol::InputEvent;
5-
use tracing::info;
5+
use midi_msg::MidiMsg;
6+
use tracing::{info, warn};
67

78
async fn run(lh: Lighthouse<TokioWebSocket>) -> Result<()> {
89
info!("Connected to the Lighthouse server");
@@ -12,7 +13,10 @@ async fn run(lh: Lighthouse<TokioWebSocket>) -> Result<()> {
1213
while let Some(msg) = stream.next().await {
1314
let event = msg?.payload;
1415
if let InputEvent::MIDI(midi) = event {
15-
info!("Got MIDI event: {:?}", midi);
16+
match MidiMsg::from_midi(&midi.data) {
17+
Ok((msg, _)) => info!("Got MIDI message: {:?}", msg),
18+
Err(e) => warn!("Could not parse MIDI message: {:?}", e),
19+
};
1620
}
1721
}
1822

0 commit comments

Comments
 (0)