Closed elmcapp closed 2 years ago
I figured out the issue but not sure how to fix it.
let source_index = 0;
println!("Source index: {}", source_index);
let source = Source::from_index(source_index).unwrap();
let source_id = source.unique_id().unwrap_or(0);
println!("Source display name: {}", source.display_name().unwrap());
println!("Source unique id: {:08x}", source_id);
let client = Client::new("Example Client").unwrap();
let callback = |event_list: &EventList, context: &mut u32| {
print!("{:08x}: {:?}", *context, event_list);
};
let mut input_port = client
.input_port_with_protocol("Example Port", Protocol::Midi10, callback)
.unwrap();
input_port.connect_source(&source, source_id).unwrap();
let mut input_line = String::new();
println!("Press Enter to Finish");
std::io::stdin()
.read_line(&mut input_line)
.expect("Failed to read line");
thread::sleep(time::Duration::from_secs(5));
input_port.disconnect_source(&source).unwrap();
When I add the sleep it will allow the code block to run and receive midi for 5 second after that then it exits. It appears to run a little different on Tauri than in Rust alone.
Can you suggest anything I can do to keep the function alive
@elmcapp your problem is not related with this library at all. The problem I see in your code is that you are blocking a Tauri command waiting for a key input with the lines std::io::stdin() .read_line(&mut input_line)
. Also, you should create and bind the CoreMIDI client to the lifecycle of the Tauri application, but you are creating and destroying it within the command context. I have not worked with Tauri before, so I can not help you with the details on how to create the client and keep it as part of the Tauri application for the whole lifecycle, sorry.
@elmcapp this is exactly what you need to know:
https://tauri.studio/docs/guides/command#accessing-managed-state
You will create a Client
as part of your application state when you build your Tauri app, and then you will pass it as a parameter to your commands when needed.
Just found out that Tauri does not allow
std::io::stdin()
.read_line(&mut input_line)
.expect("Failed to read line");
Do you have any other ideals how to block function from ending.
@elmcapp I already told you what you need to do in my previous message.
I am creating a Tauri app that can get a list of midi devices and receive midi packets. I am using your library CoreMIDI. The issue that I am having is that when using the code block to receive midi packets is that it run through the code block line by line and does not give opportunity for me to input midi from my midi device. It's like the code runs and complete without me pressing enter. It works in just using a plain Rust project just does not working when using it with Tauri
If you can help me with this I will be grateful
I have attached example of the code I created https://github.com/elmcapp/elmc-midi
Tauri setup: https://tauri.studio/docs/getting-started/setting-up-macos and you can run the project using yarn tauri dev
Also here is a video to show what's going wrong
https://user-images.githubusercontent.com/64275658/160249197-0a97c55a-3da4-4c63-95f4-8b62679b74b6.mp4