Skip to content

Commit

Permalink
Update xsynth for sf2 support / add threadpool (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaydax authored Jul 31, 2024
1 parent a428be4 commit 3defc3f
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 9 deletions.
96 changes: 93 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ egui = "0.21.0"
winit = "0.28.3"
rayon = "1.7.0"
midi-toolkit-rs = { git = "https://github.com/arduano/midi-toolkit-rs.git", rev = "a54f198" }
xsynth-core = { git = "https://github.com/arduano/xsynth.git", rev = "e300f1d" }
xsynth-realtime = { git = "https://github.com/arduano/xsynth.git", rev = "e300f1d" }
xsynth-core = { git = "https://github.com/arduano/xsynth.git", rev = "3385cd0" }
xsynth-realtime = { git = "https://github.com/arduano/xsynth.git", rev = "3385cd0" }
gen-iter = { git = "https://github.com/arduano/gen-iter.git", rev = "64e28bc" }
enum_dispatch = "0.3.11"
palette = "0.7.1"
Expand Down
5 changes: 4 additions & 1 deletion src/audio_playback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod xsynth;
pub enum AudioPlayerType {
XSynth {
buffer: f64,
use_threadpool: bool,
ignore_range: RangeInclusive<u8>,
options: ChannelInitOptions,
},
Expand All @@ -24,10 +25,12 @@ impl SimpleTemporaryPlayer {
let (xsynth, kdmapi) = match player_type.clone() {
AudioPlayerType::XSynth {
buffer,
use_threadpool,
ignore_range,
options,
} => {
let xsynth = xsynth::XSynthPlayer::new(buffer, ignore_range, options);
let xsynth =
xsynth::XSynthPlayer::new(buffer, use_threadpool, ignore_range, options);
(Some(xsynth), None)
}
AudioPlayerType::Kdmapi => {
Expand Down
9 changes: 7 additions & 2 deletions src/audio_playback/xsynth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,15 @@ pub struct XSynthPlayer {
}

impl XSynthPlayer {
pub fn new(buffer: f64, ignore_range: RangeInclusive<u8>, options: ChannelInitOptions) -> Self {
pub fn new(
buffer: f64,
use_threadpool: bool,
ignore_range: RangeInclusive<u8>,
options: ChannelInitOptions,
) -> Self {
let config = XSynthRealtimeConfig {
render_window_ms: buffer,
use_threadpool: false,
use_threadpool,
channel_init_options: options,
ignore_range,
..Default::default()
Expand Down
1 change: 1 addition & 0 deletions src/gui/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl GuiWasabiWindow {
let synth = Arc::new(RwLock::new(SimpleTemporaryPlayer::new(
AudioPlayerType::XSynth {
buffer: settings.synth.buffer_ms,
use_threadpool: settings.synth.use_threadpool,
ignore_range: settings.synth.vel_ignore.clone(),
options: convert_to_channel_init(settings),
},
Expand Down
1 change: 1 addition & 0 deletions src/gui/window/settings_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub fn draw_settings(
.unwrap()
.switch_player(AudioPlayerType::XSynth {
buffer: settings.synth.buffer_ms,
use_threadpool: settings.synth.use_threadpool,
ignore_range: settings.synth.vel_ignore.clone(),
options: convert_to_channel_init(settings),
});
Expand Down
7 changes: 6 additions & 1 deletion src/gui/window/xsynth_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn draw_xsynth_settings(
if ui.button("Browse...").clicked() {
// If windows, just use the native dialog
let sfz_path = rfd::FileDialog::new()
.add_filter("sfz", &["sfz"])
.add_filter("sfz/sf2", &["sfz", "sf2"])
.pick_file();

if let Some(sfz_path) = sfz_path {
Expand Down Expand Up @@ -141,6 +141,10 @@ pub fn draw_xsynth_settings(
ui.label("Use Effects*: ");
ui.checkbox(&mut settings.synth.use_effects, "");
ui.end_row();

ui.label("Use Threadpool*: ");
ui.checkbox(&mut settings.synth.use_threadpool, "");
ui.end_row();
});

ui.separator();
Expand All @@ -152,6 +156,7 @@ pub fn draw_xsynth_settings(
.unwrap()
.switch_player(AudioPlayerType::XSynth {
buffer: settings.synth.buffer_ms,
use_threadpool: settings.synth.use_threadpool,
ignore_range: settings.synth.vel_ignore.clone(),
options: convert_to_channel_init(settings),
});
Expand Down
2 changes: 2 additions & 0 deletions src/settings/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct WasabiConfigFileV0 {
last_key: u8,
midi_loading: usize,
buffer_ms: f64,
use_threadpool: bool,
limit_layers: bool,
layer_count: usize,
fade_out_kill: bool,
Expand All @@ -39,6 +40,7 @@ impl WasabiConfigFileV0 {
synth: SynthSettings {
synth: Synth::from(cfg.synth),
buffer_ms: cfg.buffer_ms,
use_threadpool: cfg.use_threadpool,
limit_layers: cfg.limit_layers,
layer_count: cfg.layer_count,
fade_out_kill: cfg.fade_out_kill,
Expand Down
2 changes: 2 additions & 0 deletions src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ impl Default for MidiSettings {
pub struct SynthSettings {
pub synth: Synth,
pub buffer_ms: f64,
pub use_threadpool: bool,
pub sfz_path: String,
pub limit_layers: bool,
pub layer_count: usize,
Expand All @@ -305,6 +306,7 @@ impl Default for SynthSettings {
SynthSettings {
synth: Synth::XSynth,
buffer_ms: XSynthRealtimeConfig::default().render_window_ms,
use_threadpool: false,
sfz_path: String::new(),
limit_layers: true,
layer_count: 4,
Expand Down

0 comments on commit 3defc3f

Please sign in to comment.