Skip to content

Remove KDMAPI and MIDI device options for unsupported OSes #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ vulkano-win = { git = "https://github.com/vulkano-rs/vulkano.git", rev = "4a77d3
midi-toolkit-rs = "0.1.0"
xsynth-core = { git = "https://github.com/BlackMIDIDevs/xsynth", rev = "818dbd6", features = ["serde"] }
xsynth-realtime = { git = "https://github.com/BlackMIDIDevs/xsynth", rev = "818dbd6", features = ["serde"] }
kdmapi-rs = { package = "kdmapi", git = "https://github.com/MyBlackMIDIScore/kdmapi-rs.git", rev = "e1db353" }
serde = "1.0.210"
serde_derive = "1.0.210"
serde_json = "1.0"
Expand All @@ -33,7 +32,6 @@ atomic_float = "1.1.0"
ico = "0.3.0"
rfd = "0.15.0"
open = "5.3.0"
midir = "0.10.0"
time = "0.3.36"
image = "0.25.2"
reqwest = { version = "0.12.8", features = ["json", "blocking", "native-tls-vendored"] }
Expand All @@ -44,6 +42,10 @@ num_enum = "0.7.3"
palette = "0.7.6"
colors-transform = "0.2"

[target.'cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))'.dependencies]
kdmapi-rs = { package = "kdmapi", git = "https://github.com/MyBlackMIDIScore/kdmapi-rs.git", rev = "e1db353" }
midir = "0.10.0"

[build-dependencies]
resvg = { version = "0.31.0", default-features = false }
ico = "0.3.0"
Expand Down
6 changes: 5 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,9 @@ fn main() {
icon_dir.write(File::create(icon_path).unwrap()).unwrap();

#[cfg(not(windows))]
println!("cargo:rerun-if-changed=assets/logo.svg")
println!("cargo:rerun-if-changed=assets/logo.svg");

#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
println!("cargo:rustc-cfg=supported_os");
println!("cargo::rustc-check-cfg=cfg(supported_os)");
}
16 changes: 16 additions & 0 deletions src/audio_playback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ use crate::{

mod xsynth;
pub use xsynth::*;

#[cfg(supported_os)]
mod kdmapi;
#[cfg(supported_os)]
pub use kdmapi::*;

#[cfg(supported_os)]
mod midiout;
#[cfg(supported_os)]
pub use midiout::*;

enum MidiAudioPlayer {
XSynth(XSynthPlayer),
#[cfg(supported_os)]
Kdmapi(KdmapiPlayer),
#[cfg(supported_os)]
MidiDevice(MidiDevicePlayer),
None,
}
Expand All @@ -36,7 +44,9 @@ impl WasabiAudioPlayer {
pub fn push_events(&self, data: impl Iterator<Item = u32>) {
match &mut *self.0.write().unwrap() {
MidiAudioPlayer::XSynth(player) => player.push_events(data),
#[cfg(supported_os)]
MidiAudioPlayer::Kdmapi(player) => player.push_events(data),
#[cfg(supported_os)]
MidiAudioPlayer::MidiDevice(player) => player.push_events(data),
_ => {}
}
Expand All @@ -45,6 +55,7 @@ impl WasabiAudioPlayer {
pub fn configure(&self, settings: &SynthSettings) {
match &mut *self.0.write().unwrap() {
MidiAudioPlayer::XSynth(player) => player.configure(&settings.xsynth),
#[cfg(supported_os)]
MidiAudioPlayer::Kdmapi(player) => player.configure(&settings.kdmapi),
_ => {}
}
Expand All @@ -60,6 +71,7 @@ impl WasabiAudioPlayer {
MidiAudioPlayer::XSynth(player) => {
player.set_soundfonts(soundfonts, loading_status, errors)
}
#[cfg(supported_os)]
MidiAudioPlayer::Kdmapi(player) => player.set_soundfonts(soundfonts, errors),
_ => {}
}
Expand All @@ -68,7 +80,9 @@ impl WasabiAudioPlayer {
pub fn reset(&self) {
match &mut *self.0.write().unwrap() {
MidiAudioPlayer::XSynth(player) => player.reset(),
#[cfg(supported_os)]
MidiAudioPlayer::Kdmapi(player) => player.reset(),
#[cfg(supported_os)]
MidiAudioPlayer::MidiDevice(player) => player.reset(),
_ => {}
}
Expand All @@ -88,13 +102,15 @@ impl WasabiAudioPlayer {
Synth::XSynth => {
MidiAudioPlayer::XSynth(XSynthPlayer::new(settings.xsynth.config.clone()))
}
#[cfg(supported_os)]
Synth::Kdmapi => match KdmapiPlayer::new() {
Ok(kdmapi) => MidiAudioPlayer::Kdmapi(kdmapi),
Err(e) => {
errors.error(&e);
MidiAudioPlayer::None
}
},
#[cfg(supported_os)]
Synth::MidiDevice => match MidiDevicePlayer::new(settings.midi_device.clone()) {
Ok(midiout) => MidiAudioPlayer::MidiDevice(midiout),
Err(e) => {
Expand Down
2 changes: 2 additions & 0 deletions src/gui/window/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::utils;
pub enum WasabiError {
MidiLoadError(MIDILoadError),
SoundFontLoadError(LoadSfError),
#[cfg(supported_os)]
SynthError(String),
FilesystemError(std::io::Error),
SettingsError(String),
Expand All @@ -33,6 +34,7 @@ impl fmt::Display for WasabiError {
MIDILoadError::FileTooBig => write!(f, "MIDI Load Error: File Too Big"),
},
WasabiError::SoundFontLoadError(e) => write!(f, "Error Parsing SoundFont: {e}"),
#[cfg(supported_os)]
WasabiError::SynthError(e) => write!(f, "Synth Error: {e}"),
WasabiError::FilesystemError(e) => write!(f, "Filesystem Error: {e}"),
WasabiError::SettingsError(e) => write!(f, "Settings Error: {e}"),
Expand Down
19 changes: 16 additions & 3 deletions src/gui/window/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct FilePalette {
pub selected: bool,
}

#[cfg(supported_os)]
#[derive(Clone)]
struct MidiDevice {
pub name: String,
Expand All @@ -32,6 +33,7 @@ struct MidiDevice {

pub struct SettingsWindow {
palettes: Vec<FilePalette>,
#[cfg(supported_os)]
midi_devices: Vec<MidiDevice>,
sf_list: EguiSFList,
}
Expand All @@ -45,6 +47,7 @@ impl SettingsWindow {

Self {
palettes: Vec::new(),
#[cfg(supported_os)]
midi_devices: Vec::new(),
sf_list,
}
Expand Down Expand Up @@ -100,11 +103,15 @@ impl SettingsWindow {
"\u{1f3b9} Synth",
)
});

#[cfg(supported_os)]
let sf_kdmapi_check = settings.synth.synth == Synth::Kdmapi
&& !settings.synth.kdmapi.use_om_sflist;
#[cfg(not(supported_os))]
let sf_kdmapi_check = false;
columns[3].vertical_centered_justified(|ui| {
ui.add_enabled_ui(
settings.synth.synth == Synth::XSynth
|| (settings.synth.synth == Synth::Kdmapi
&& !settings.synth.kdmapi.use_om_sflist),
settings.synth.synth == Synth::XSynth || sf_kdmapi_check,
|ui| {
ui.selectable_value(
&mut state.settings_tab,
Expand Down Expand Up @@ -183,6 +190,12 @@ impl SettingsWindow {
Ok(())
}

#[cfg(not(supported_os))]
pub fn load_midi_devices(&mut self, _settings: &mut WasabiSettings) -> Result<(), WasabiError> {
Ok(())
}

#[cfg(supported_os)]
pub fn load_midi_devices(&mut self, settings: &mut WasabiSettings) -> Result<(), WasabiError> {
self.midi_devices.clear();
let con = midir::MidiOutput::new("wasabi")
Expand Down
6 changes: 6 additions & 0 deletions src/gui/window/settings/synth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use crate::{

use super::SettingsWindow;

#[cfg(supported_os)]
mod kdmapi;
#[cfg(supported_os)]
mod mididevice;
mod xsynth;

Expand Down Expand Up @@ -34,11 +36,13 @@ impl SettingsWindow {
Synth::XSynth,
Synth::XSynth.as_str(),
);
#[cfg(supported_os)]
ui.selectable_value(
&mut settings.synth.synth,
Synth::Kdmapi,
Synth::Kdmapi.as_str(),
);
#[cfg(supported_os)]
ui.selectable_value(
&mut settings.synth.synth,
Synth::MidiDevice,
Expand Down Expand Up @@ -80,7 +84,9 @@ impl SettingsWindow {

match settings.synth.synth {
Synth::XSynth => self.show_xsynth_settings(ui, settings, state, width),
#[cfg(supported_os)]
Synth::Kdmapi => self.show_kdmapi_settings(ui, settings, state, width),
#[cfg(supported_os)]
Synth::MidiDevice => self.show_mididevice_settings(ui, settings, state, width),
Synth::None => {
ui.label("No Settings");
Expand Down
6 changes: 6 additions & 0 deletions src/settings/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ impl FromStr for MidiParsing {
pub enum Synth {
#[default]
XSynth = 0,
#[cfg(supported_os)]
Kdmapi = 1,
#[cfg(supported_os)]
MidiDevice = 2,
None = 3,
}
Expand All @@ -55,7 +57,9 @@ impl Synth {
pub const fn as_str(self) -> &'static str {
match self {
Synth::XSynth => "Built-In (XSynth)",
#[cfg(supported_os)]
Synth::Kdmapi => "KDMAPI",
#[cfg(supported_os)]
Synth::MidiDevice => "MIDI Device",
Synth::None => "None",
}
Expand All @@ -68,7 +72,9 @@ impl FromStr for Synth {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"xsynth" => Ok(Synth::XSynth),
#[cfg(supported_os)]
"kdmapi" => Ok(Synth::Kdmapi),
#[cfg(supported_os)]
"mididevice" => Ok(Synth::MidiDevice),
"none" => Ok(Synth::None),
s => Err(format!(
Expand Down
3 changes: 3 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use serde_json::Value;
use std::thread;
use std::{collections::HashMap, ops::RangeInclusive};

#[cfg(supported_os)]
use crate::settings::WasabiSoundfont;
use crate::{gui::window::WasabiError, state::WasabiState};

Expand Down Expand Up @@ -75,6 +76,7 @@ pub fn check_for_updates(state: &WasabiState) {
});
}

#[cfg(supported_os)]
pub fn create_om_sf_list(list: &[WasabiSoundfont]) -> String {
let mut out = String::new();

Expand All @@ -101,6 +103,7 @@ pub fn create_om_sf_list(list: &[WasabiSoundfont]) -> String {
out
}

#[cfg(supported_os)]
pub fn create_reset_midi_messages() -> Vec<u32> {
let mut out = Vec::new();

Expand Down
Loading