Skip to content

Commit

Permalink
Add a new PolySynth plugin example, plus various QoL improvements (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
prokopyl authored Nov 23, 2023
1 parent 94656eb commit edc57ea
Show file tree
Hide file tree
Showing 29 changed files with 1,710 additions and 156 deletions.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
resolver = "2"
members = [
"common",
"plugin/examples/gain",
"host",
"host/examples/cpal",
"plugin",
"plugin/examples/gain",
"plugin/examples/polysynth",
"extensions",
"test-host"
]

[workspace.dependencies]
clack-plugin = { path = "./plugin" }
clack-host = { path = "./host" }
clack-extensions = { path = "./extensions" }

selfie = { git = 'https://github.com/prokopyl/selfie', rev = '726013fc94835b6f24918ba822a49e5c3b2a3b25' }
14 changes: 13 additions & 1 deletion common/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use crate::events::spaces::*;
use clap_sys::events::clap_event_header;
use std::fmt::{Debug, Formatter};
use std::marker::PhantomData;

pub mod event_types;
Expand Down Expand Up @@ -50,7 +51,6 @@ pub unsafe trait Event<'a>: AsRef<UnknownEvent<'a>> + Sized + 'a {
}

#[repr(transparent)]
#[derive(Debug)]
pub struct UnknownEvent<'a> {
_sysex_lifetime: PhantomData<&'a u8>,
data: [u8],
Expand Down Expand Up @@ -159,6 +159,18 @@ where
}
}

impl<'a> Debug for UnknownEvent<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self.as_core_event() {
Some(e) => Debug::fmt(&e, f),
None => f
.debug_struct("UnknownEvent")
.field("header", self.header())
.finish(),
}
}
}

impl<'a> AsRef<UnknownEvent<'a>> for UnknownEvent<'a> {
#[inline]
fn as_ref(&self) -> &UnknownEvent<'a> {
Expand Down
3 changes: 3 additions & 0 deletions common/src/events/event_types/midi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl Eq for MidiEvent {}
impl Debug for MidiEvent {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("MidiEvent")
.field("header", &self.header())
.field("port_index", &self.inner.port_index)
.field("data", &self.inner.data)
.finish()
Expand Down Expand Up @@ -163,6 +164,7 @@ impl<'a> Eq for MidiSysExEvent<'a> {}
impl<'a> Debug for MidiSysExEvent<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("MidiSysexEvent")
.field("header", &self.header())
.field("port_index", &self.inner.port_index)
.field("data", &self.data())
.finish()
Expand Down Expand Up @@ -230,6 +232,7 @@ impl Eq for Midi2Event {}
impl Debug for Midi2Event {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Midi2Event")
.field("header", &self.header())
.field("port_index", &self.inner.port_index)
.field("data", &self.inner.data)
.finish()
Expand Down
55 changes: 44 additions & 11 deletions common/src/events/event_types/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clap_sys::events::*;
use std::fmt::{Debug, Formatter};
use std::marker::PhantomData;

#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Copy, Clone, PartialEq)]
#[repr(C)]
pub struct NoteOnEvent(pub NoteEvent<Self>);

Expand All @@ -20,7 +20,13 @@ impl<'a> AsRef<UnknownEvent<'a>> for NoteOnEvent {
}
}

#[derive(Debug, Copy, Clone, PartialEq)]
impl Debug for NoteOnEvent {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fmt_note_event(&self.0, f, "NoteOnEvent")
}
}

#[derive(Copy, Clone, PartialEq)]
#[repr(C)]
pub struct NoteOffEvent(pub NoteEvent<Self>);

Expand All @@ -36,7 +42,13 @@ impl<'a> AsRef<UnknownEvent<'a>> for NoteOffEvent {
}
}

#[derive(Debug, Copy, Clone, PartialEq)]
impl Debug for NoteOffEvent {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fmt_note_event(&self.0, f, "NoteOffEvent")
}
}

#[derive(Copy, Clone, PartialEq)]
#[repr(C)]
pub struct NoteChokeEvent(pub NoteEvent<Self>);

Expand All @@ -52,7 +64,13 @@ impl<'a> AsRef<UnknownEvent<'a>> for NoteChokeEvent {
}
}

#[derive(Debug, Copy, Clone, PartialEq)]
impl Debug for NoteChokeEvent {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fmt_note_event(&self.0, f, "NoteChokeEvent")
}
}

#[derive(Copy, Clone, PartialEq)]
#[repr(C)]
pub struct NoteEndEvent(pub NoteEvent<Self>);

Expand All @@ -68,6 +86,12 @@ impl<'a> AsRef<UnknownEvent<'a>> for NoteEndEvent {
}
}

impl Debug for NoteEndEvent {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fmt_note_event(&self.0, f, "NoteEndEvent")
}
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct NoteEvent<E> {
Expand Down Expand Up @@ -161,12 +185,21 @@ impl<E> PartialEq for NoteEvent<E> {

impl<E> Debug for NoteEvent<E> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("NoteEvent")
.field("port_index", &self.inner.port_index)
.field("channel", &self.inner.channel)
.field("key", &self.inner.key)
.field("velocity", &self.inner.velocity)
.field("note_id", &self.inner.note_id)
.finish()
fmt_note_event(self, f, "NoteEvent")
}
}

fn fmt_note_event<E>(
event: &NoteEvent<E>,
f: &mut Formatter<'_>,
event_name: &'static str,
) -> core::fmt::Result {
f.debug_struct(event_name)
.field("header", event.header())
.field("port_index", &event.inner.port_index)
.field("channel", &event.inner.channel)
.field("key", &event.inner.key)
.field("velocity", &event.inner.velocity)
.field("note_id", &event.inner.note_id)
.finish()
}
5 changes: 5 additions & 0 deletions common/src/events/event_types/param_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl PartialEq for ParamValueEvent {
impl Debug for ParamValueEvent {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ParamValueEvent")
.field("header", &self.header())
.field("port_index", &self.inner.port_index)
.field("channel", &self.inner.channel)
.field("key", &self.inner.key)
Expand Down Expand Up @@ -242,6 +243,7 @@ impl PartialEq for ParamModEvent {
impl Debug for ParamModEvent {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ParamModEvent")
.field("header", &self.header())
.field("port_index", &self.inner.port_index)
.field("channel", &self.inner.channel)
.field("key", &self.inner.key)
Expand Down Expand Up @@ -290,6 +292,8 @@ impl ParamGestureBeginEvent {
impl Debug for ParamGestureBeginEvent {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ParamGestureBeginEvent")
.field("header", &self.header())
.field("header", &self.header())
.field("param_id", &self.inner.param_id)
.finish()
}
Expand Down Expand Up @@ -341,6 +345,7 @@ impl ParamGestureEndEvent {
impl Debug for ParamGestureEndEvent {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ParamGestureEndEvent")
.field("header", &self.header())
.field("header", self.header())
.field("param_id", &self.inner.param_id)
.finish()
Expand Down
6 changes: 6 additions & 0 deletions common/src/events/io.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
//! Various utilities and types to help processing Input and Output events.

#![deny(missing_docs)]

mod batcher;
mod buffer;
mod implementation;
mod input;
mod merger;
mod output;

pub use batcher::*;
pub use buffer::*;
pub use implementation::*;
pub use input::*;
Expand Down
Loading

0 comments on commit edc57ea

Please sign in to comment.