Skip to content

Commit

Permalink
Release v0.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Aug 22, 2023
1 parent 80f379c commit eec3a75
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[package]
name = "djio"
description = "DJ Hardware Control(ler) Support"
version = "0.0.10"
version = "0.0.11"
license = "MPL-2.0"
readme = "README.md"
repository = "https://github.com/uklotzde/djio"
Expand Down
28 changes: 13 additions & 15 deletions examples/midi_dj_controller_hotplug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::{
use djio::{
consume_midi_input_event,
devices::{korg_kaoss_dj, pioneer_ddj_400, MIDI_DJ_CONTROLLER_DESCRIPTORS},
ControlInputEventSink, MidiDeviceDescriptor, MidiInputConnector, MidiInputEventDecoder,
MidiInputGateway, MidiInputHandler, MidiOutputConnection, MidiOutputGateway,
BoxedMidiOutputConnection, ControlInputEventSink, MidiDeviceDescriptor, MidiInputConnector,
MidiInputEventDecoder, MidiInputGateway, MidiInputHandler, MidiOutputGateway,
MidiPortDescriptor, MidirDevice, MidirDeviceManager, OutputResult, PortIndex,
PortIndexGenerator, TimeStamp,
};
Expand Down Expand Up @@ -103,37 +103,35 @@ impl djio::NewMidiInputGateway for NewMidiInputGateway {
}
}

type DynMidiOutputConnection = dyn MidiOutputConnection + Send + 'static;

trait Controller {
// ...
}

trait MidiController: Controller + MidiOutputGateway<Box<DynMidiOutputConnection>> {}
trait MidiController: Controller + MidiOutputGateway<BoxedMidiOutputConnection> {}

impl<T> MidiController for T where T: Controller + MidiOutputGateway<Box<DynMidiOutputConnection>> {}
impl<T> MidiController for T where T: Controller + MidiOutputGateway<BoxedMidiOutputConnection> {}

#[derive(Default)]
struct KorgKaossDj {
output_gateway: Option<korg_kaoss_dj::OutputGateway<Box<DynMidiOutputConnection>>>,
output_gateway: Option<korg_kaoss_dj::OutputGateway<BoxedMidiOutputConnection>>,
}

impl Controller for KorgKaossDj {}

impl MidiOutputGateway<Box<DynMidiOutputConnection>> for KorgKaossDj {
impl MidiOutputGateway<BoxedMidiOutputConnection> for KorgKaossDj {
fn attach_midi_output_connection(
&mut self,
connection: &mut Option<Box<DynMidiOutputConnection>>,
connection: &mut Option<BoxedMidiOutputConnection>,
) -> OutputResult<()> {
debug_assert!(self.output_gateway.is_none());
let mut output_gateway =
korg_kaoss_dj::OutputGateway::<Box<DynMidiOutputConnection>>::default();
korg_kaoss_dj::OutputGateway::<BoxedMidiOutputConnection>::default();
output_gateway.attach_midi_output_connection(connection)?;
self.output_gateway = Some(output_gateway);
Ok(())
}

fn detach_midi_output_connection(&mut self) -> Option<Box<DynMidiOutputConnection>> {
fn detach_midi_output_connection(&mut self) -> Option<BoxedMidiOutputConnection> {
self.output_gateway
.take()
.and_then(|mut output_gateway| output_gateway.detach_midi_output_connection())
Expand All @@ -142,7 +140,7 @@ impl MidiOutputGateway<Box<DynMidiOutputConnection>> for KorgKaossDj {

fn new_midi_controller<I>(
device: &MidirDevice<I>,
output_connection: &mut Option<Box<DynMidiOutputConnection>>,
output_connection: &mut Option<BoxedMidiOutputConnection>,
) -> OutputResult<Option<Box<dyn MidiController>>>
where
I: MidiInputGateway + Send,
Expand Down Expand Up @@ -175,7 +173,7 @@ impl ControlInputEventSink for LoggingInputPortEventSink {
fn reconnect_midi_controller<I>(
device: &mut MidirDevice<I::MidiInputGateway>,
new_input_gateway: Option<&I>,
_detached_output_connection: Option<Box<DynMidiOutputConnection>>,
_detached_output_connection: Option<BoxedMidiOutputConnection>,
) -> anyhow::Result<Option<Box<dyn MidiController>>>
where
I: djio::NewMidiInputGateway,
Expand All @@ -194,7 +192,7 @@ where
fn disconnect_midi_controller(
device: &mut MidirDevice<MidiLogger>,
mut controller: Option<Box<dyn MidiController>>,
) -> Option<Box<DynMidiOutputConnection>> {
) -> Option<BoxedMidiOutputConnection> {
let detached_output_connection = controller
.as_mut()
.and_then(|boxed| boxed.as_mut().detach_midi_output_connection());
Expand Down Expand Up @@ -250,7 +248,7 @@ fn run() -> anyhow::Result<()> {
let device_name = midir_device.descriptor().device.name();

println!("Starting endless loop, press CTRL-C to exit...");
let mut output_connection: Option<Box<DynMidiOutputConnection>> = None;
let mut output_connection: Option<BoxedMidiOutputConnection> = None;
let mut controller: Option<Box<dyn MidiController>> = None;
loop {
match (
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,10 @@ pub use self::midi::midir::{
};
#[cfg(feature = "midi")]
pub use self::midi::{
consume_midi_input_event, MidiControlOutputGateway, MidiDeviceDescriptor, MidiInputConnector,
MidiInputDecodeError, MidiInputEventDecoder, MidiInputGateway, MidiInputHandler,
MidiOutputConnection, MidiOutputGateway, MidiPortDescriptor, NewMidiInputGateway,
consume_midi_input_event, BoxedMidiOutputConnection, MidiControlOutputGateway,
MidiDeviceDescriptor, MidiInputConnector, MidiInputDecodeError, MidiInputEventDecoder,
MidiInputGateway, MidiInputHandler, MidiOutputConnection, MidiOutputGateway,
MidiPortDescriptor, NewMidiInputGateway,
};

#[cfg(feature = "experimental-param")]
Expand Down
2 changes: 2 additions & 0 deletions src/midi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pub trait MidiOutputConnection {
fn send_midi_output(&mut self, output: &[u8]) -> OutputResult<()>;
}

pub type BoxedMidiOutputConnection = Box<dyn MidiOutputConnection + Send + 'static>;

impl<T> MidiOutputConnection for Box<T>
where
T: MidiOutputConnection + ?Sized,
Expand Down

0 comments on commit eec3a75

Please sign in to comment.