-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1124 Make it possible to transform to another MIDI input device
- Loading branch information
Showing
11 changed files
with
426 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,59 @@ | ||
use helgoboss_learn::RawMidiEvent; | ||
use reaper_medium::MidiInputDeviceId; | ||
|
||
#[derive(Debug)] | ||
pub struct MidiTransformationContainer { | ||
events: Vec<RawMidiEvent>, | ||
/// Emptied right after reading the input buffer of a device. | ||
same_device_events: Vec<RawMidiEvent>, | ||
/// Emptied later, after reading the input buffers of **all** devices (should have a larger capacity). | ||
other_device_events: Vec<DevQualifiedRawMidiEvent>, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct DevQualifiedRawMidiEvent { | ||
pub input_device_id: MidiInputDeviceId, | ||
pub event: RawMidiEvent, | ||
} | ||
|
||
impl DevQualifiedRawMidiEvent { | ||
fn new(input_device_id: MidiInputDeviceId, event: RawMidiEvent) -> Self { | ||
Self { | ||
input_device_id, | ||
event, | ||
} | ||
} | ||
} | ||
|
||
impl Default for MidiTransformationContainer { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl MidiTransformationContainer { | ||
pub fn with_capacity(capacity: usize) -> Self { | ||
pub fn new() -> Self { | ||
Self { | ||
events: Vec::with_capacity(capacity), | ||
same_device_events: Vec::with_capacity(100), | ||
other_device_events: Vec::with_capacity(900), | ||
} | ||
} | ||
|
||
pub fn push(&mut self, device: Option<MidiInputDeviceId>, event: RawMidiEvent) { | ||
if let Some(dev) = device { | ||
self.other_device_events | ||
.push(DevQualifiedRawMidiEvent::new(dev, event)); | ||
} else { | ||
self.same_device_events.push(event); | ||
} | ||
} | ||
|
||
pub fn push(&mut self, event: RawMidiEvent) { | ||
self.events.push(event); | ||
pub fn drain_same_device_events(&mut self) -> impl Iterator<Item = RawMidiEvent> + '_ { | ||
self.same_device_events.drain(..) | ||
} | ||
|
||
pub fn drain(&mut self) -> impl Iterator<Item = RawMidiEvent> + '_ { | ||
self.events.drain(..) | ||
pub fn drain_other_device_events( | ||
&mut self, | ||
) -> impl Iterator<Item = DevQualifiedRawMidiEvent> + '_ { | ||
self.other_device_events.drain(..) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.