Skip to content

Commit

Permalink
Merge pull request #66 from jacobh/feature/midi-macos-only
Browse files Browse the repository at this point in the history
conditional coremidi
  • Loading branch information
jacobh committed Aug 8, 2020
2 parents fd23639 + e9b1127 commit e17eeb8
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 27 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/roller.yml
@@ -0,0 +1,24 @@
name: Roller

on:
push:
branches: "**"

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- name: Cache target dirs
uses: actions/cache@v2
with:
path: |
**/target
key: ${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
- name: Check
run: cargo check --verbose
22 changes: 0 additions & 22 deletions .github/workflows/rust.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/web_ui.yml
@@ -0,0 +1,30 @@
name: Web UI

on:
push:
branches: "**"

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- name: Install wasm32 target
uses: actions-rs/toolchain@v1
with:
toolchain: stable
default: true
target: wasm32-unknown-unknown
- name: Cache target dirs
uses: actions/cache@v2
with:
path: |
**/target
key: ${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
- name: Check Web UI
run: (cd web_ui && make check)
8 changes: 5 additions & 3 deletions midi/Cargo.toml
Expand Up @@ -7,7 +7,9 @@ edition = "2018"
[dependencies]
num-traits = "*"
num-derive = "*"
coremidi = "*"
async-std = "*"
async-std = { version = "*", features = ["unstable"] }
thiserror = "1.0"
serde = "1.0"
serde = { version = "*", features = ["derive"] }

[target.'cfg(target_os = "macos")'.dependencies]
coremidi = "*"
32 changes: 30 additions & 2 deletions midi/src/io.rs
Expand Up @@ -3,6 +3,9 @@ use std::pin::Pin;
use std::time::Duration;
use thiserror::Error;

#[cfg(target_os = "macos")]
extern crate coremidi;

use crate::{MidiEvent, MidiMessageStream};

#[derive(Debug, Error)]
Expand All @@ -15,13 +18,18 @@ pub enum MidiIoError {
DestinationNotFound,
}

#[cfg(target_os = "macos")]
#[derive(Debug)]
struct MidiInputState {
_client: coremidi::Client,
_input_port: coremidi::InputPort,
_source: coremidi::Source,
}

#[cfg(not(target_os = "macos"))]
#[derive(Debug)]
struct MidiInputState {}

// TODO unclear if this is legitimate
unsafe impl Send for MidiInputState {}
unsafe impl Sync for MidiInputState {}
Expand All @@ -32,6 +40,7 @@ pub struct MidiInput {
input_receiver: async_std::sync::Receiver<MidiEvent>,
}
impl MidiInput {
#[cfg(target_os = "macos")]
pub fn new(name: &str) -> Result<MidiInput, MidiIoError> {
let client = coremidi::Client::new(&format!("roller-input-{}", name))
.map_err(|_| MidiIoError::InitFailed)?;
Expand Down Expand Up @@ -76,6 +85,10 @@ impl MidiInput {
input_receiver,
})
}
#[cfg(not(target_os = "macos"))]
pub fn new(name: &str) -> Result<MidiInput, MidiIoError> {
unimplemented!()
}
}
impl Stream for MidiInput {
type Item = MidiEvent;
Expand All @@ -87,14 +100,25 @@ impl Stream for MidiInput {
}
}

#[cfg(target_os = "macos")]
#[derive(Debug)]
struct MidiOutputState {
client: coremidi::Client,
}

#[cfg(not(target_os = "macos"))]
#[derive(Debug)]
struct MidiOutputState {}

unsafe impl Send for MidiOutput {}
unsafe impl Sync for MidiOutput {}
#[derive(Debug)]
pub struct MidiOutput {
_client: coremidi::Client,
state: MidiOutputState,
output_sender: async_std::sync::Sender<Vec<u8>>,
}
impl MidiOutput {
#[cfg(target_os = "macos")]
pub fn new(name: &str) -> Result<MidiOutput, MidiIoError> {
let client = coremidi::Client::new(&format!("roller-output-{}", name))
.map_err(|_| MidiIoError::InitFailed)?;
Expand Down Expand Up @@ -122,10 +146,14 @@ impl MidiOutput {
});

Ok(MidiOutput {
_client: client,
state: MidiOutputState { client },
output_sender,
})
}
#[cfg(not(target_os = "macos"))]
pub fn new(name: &str) -> Result<MidiOutput, MidiIoError> {
unimplemented!()
}
pub async fn send_packet(&self, packet: impl Into<Vec<u8>>) {
self.output_sender.send(packet.into()).await
}
Expand Down

0 comments on commit e17eeb8

Please sign in to comment.