From ca8ee979ea9131058aa100e321797d8e45220826 Mon Sep 17 00:00:00 2001 From: GHOSCHT <31184695+GHOSCHT@users.noreply.github.com> Date: Mon, 23 Dec 2024 22:02:43 +0100 Subject: [PATCH] Rename --- .../midi_service.rs => midi_client.rs} | 2 +- .../midir_service.rs => midir_client_impl.rs} | 37 +++++++++++-------- src/clients/mod.rs | 8 ++-- 3 files changed, 27 insertions(+), 20 deletions(-) rename src/clients/{services/midi_service.rs => midi_client.rs} (88%) rename src/clients/{services/midir_service.rs => midir_client_impl.rs} (52%) diff --git a/src/clients/services/midi_service.rs b/src/clients/midi_client.rs similarity index 88% rename from src/clients/services/midi_service.rs rename to src/clients/midi_client.rs index 1329d10..a89d61b 100644 --- a/src/clients/services/midi_service.rs +++ b/src/clients/midi_client.rs @@ -3,7 +3,7 @@ use shaku::{self, Interface}; pub type MidiConnectionCallback = Box; #[cfg_attr(test, mockall::automock)] -pub trait MidiService: Interface { +pub trait MidiClient: Interface { fn ports(&self) -> Vec; fn connect(&self, port: MP, port_name: &str, callback: MidiConnectionCallback) -> (); } diff --git a/src/clients/services/midir_service.rs b/src/clients/midir_client_impl.rs similarity index 52% rename from src/clients/services/midir_service.rs rename to src/clients/midir_client_impl.rs index 33cfaef..1e7dc86 100644 --- a/src/clients/services/midir_service.rs +++ b/src/clients/midir_client_impl.rs @@ -1,31 +1,38 @@ -use midir::{MidiInput, MidiInputPort}; +use midir::{MidiInput, MidiInputPort, Ignore}; use shaku::{self, Component}; -use super::midi_service::{MidiConnectionCallback, MidiPort, MidiService}; +use super::midi_client::{MidiClient, MidiConnectionCallback, MidiPort}; use std::time; fn create_input(client_name: &str) -> MidiInput { - MidiInput::new(client_name).expect("Creating MIDI device failed") + let mut input = MidiInput::new(client_name).expect("Creating MIDI device failed"); + input.ignore(Ignore::None); + return input; } #[derive(Component)] -#[shaku(interface = MidiService)] -pub struct MidirService { +#[shaku(interface = MidiClient)] +pub struct MidirClientImpl { client_name: String, } -impl MidiService for MidirService { - fn ports(&self) -> Vec { +impl MidiClient for MidirClientImpl { + fn ports(&self) -> Vec { let midi_in = create_input(&self.client_name); midi_in .ports() .iter() - .map(|p| MidirPort::new(p.clone(), self.client_name.clone())) // Cast to Box + .map(|p| MidirPortImpl::new(p.clone(), self.client_name.clone())) // Cast to Box .collect() } - fn connect(&self, port: MidirPort, port_name: &str, callback: MidiConnectionCallback) -> () { + fn connect( + &self, + port: MidirPortImpl, + port_name: &str, + callback: MidiConnectionCallback, + ) -> () { let midi_in = MidiInput::new(&self.client_name).expect("Creating MIDI device failed"); - let connection = midi_in.connect( + let _connection = midi_in.connect( port.get_port(), port_name, move |_, message, _| callback(message), @@ -37,21 +44,21 @@ impl MidiService for MidirService { } } -pub struct MidirPort { +pub struct MidirPortImpl { port: MidiInputPort, client_name: String, } -impl MidiPort for MidirPort { +impl MidiPort for MidirPortImpl { fn name(&self) -> String { let midi_in = create_input(&self.client_name); midi_in.port_name(&self.port).unwrap() } } -impl MidirPort { - fn new(port: MidiInputPort, client_name: String) -> MidirPort { - MidirPort { port, client_name } +impl MidirPortImpl { + fn new(port: MidiInputPort, client_name: String) -> MidirPortImpl { + MidirPortImpl { port, client_name } } fn get_port(&self) -> &MidiInputPort { &self.port diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 2e1bc3e..d8c9e54 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -1,5 +1,5 @@ pub mod midi; -mod services { - pub mod midi_service; - pub mod midir_service; -} +pub mod midi_client; +pub mod midir_client_impl; +pub mod midi_service; +pub mod midi_service_impl;