Skip to content

Commit f5b5fea

Browse files
committed
Add example for MIDI events
1 parent 82936e4 commit f5b5fea

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use clap::Parser;
2+
use futures::StreamExt;
3+
use lighthouse_client::{protocol::Authentication, Lighthouse, Result, TokioWebSocket, LIGHTHOUSE_URL};
4+
use lighthouse_protocol::InputEvent;
5+
use tracing::info;
6+
7+
async fn run(lh: Lighthouse<TokioWebSocket>) -> Result<()> {
8+
info!("Connected to the Lighthouse server");
9+
10+
// Stream input events
11+
let mut stream = lh.stream_input().await?;
12+
while let Some(msg) = stream.next().await {
13+
let event = msg?.payload;
14+
if let InputEvent::MIDI(midi) = event {
15+
info!("Got MIDI event: {:?}", midi);
16+
}
17+
}
18+
19+
Ok(())
20+
}
21+
22+
#[derive(Parser)]
23+
struct Args {
24+
/// The username.
25+
#[arg(short, long, env = "LIGHTHOUSE_USER")]
26+
username: String,
27+
/// The API token.
28+
#[arg(short, long, env = "LIGHTHOUSE_TOKEN")]
29+
token: String,
30+
/// The server URL.
31+
#[arg(long, env = "LIGHTHOUSE_URL", default_value = LIGHTHOUSE_URL)]
32+
url: String,
33+
}
34+
35+
#[tokio::main(flavor = "current_thread")]
36+
async fn main() -> Result<()> {
37+
tracing_subscriber::fmt().init();
38+
_ = dotenvy::dotenv();
39+
40+
let args = Args::parse();
41+
let auth = Authentication::new(&args.username, &args.token);
42+
let lh = Lighthouse::connect_with_tokio_to(&args.url, auth).await?;
43+
44+
run(lh).await
45+
}

0 commit comments

Comments
 (0)