Skip to content

Commit 975f3fb

Browse files
committed
get sound font file from both exe path and current dircetory
1 parent 9b45496 commit 975f3fb

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
lines changed

apps/notation_viewer/Makefile.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ dependencies = ["build-web", "basic-http-server"]
5151
disabled = true
5252

5353
[tasks.release-inspector]
54-
args = ["bundle", "--release", "--features", "inspector", "@@split(CARGO_RELEASE_ARGS, )"]
54+
args = ["bundle", "--features", "inspector", "@@split(CARGO_RELEASE_ARGS, )"]
5555
command = "cargo"
5656

5757
[tasks.release-native]
58-
args = ["bundle", "--release", "--features", "native", "@@split(CARGO_RELEASE_ARGS, )"]
58+
args = ["bundle", "--features", "native", "@@split(CARGO_RELEASE_ARGS, )"]
5959
command = "cargo"
60+
dependencies = ["build-native"]
6061

6162
[tasks.release-web]
6263
script_runner = "@shell"

apps/notation_viewer/release-viewer_osx.bash

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
cd `dirname $(readlink -f "$0")`
44

5-
cargo make release-native
5+
# cargo make --profile release release-native
6+
7+
cargo build --release --features native
8+
cargo bundle --release --features native
9+
610
cd ../../
7-
rm -rf ../../target/release/osx/notation_viewer.app
11+
rm -rf release/osx/notation_viewer.app
812
cp -vr target/release/bundle/osx/notation_viewer.app/ release/osx/
9-
cd release/osx/notation_viewer.app/Content/MacOS
13+
cd release/osx/notation_viewer.app/Contents/MacOS
1014
ln -s ../Resources/assets .
1115
cd ../../
1216

crates/notation_midi/src/native/midi_synth.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::path::PathBuf;
2+
13
use helgoboss_midi::StructuredShortMessage;
24

35
use crate::prelude::{MidiMessage, MidiSettings, MidiState};
@@ -10,16 +12,51 @@ pub struct MidiSynth {
1012
buffer: DoubleAudioBuffer,
1113
}
1214
impl MidiSynth {
15+
pub const SOUND_FONT: &'static str = "sblive";
1316
fn new(synth: fluidlite::Synth) -> Self {
1417
Self {
1518
synth,
1619
buffer: DoubleAudioBuffer::new(),
1720
}
1821
}
22+
fn check_path(root: PathBuf, name: &str) -> Option<PathBuf> {
23+
let mut path = root.clone();
24+
path.push("assets");
25+
path.push(name);
26+
path.set_extension("sf2");
27+
if path.exists() {
28+
Some(path)
29+
} else {
30+
println!("MidiSynth check_path() not exist: {:?} {} -> {:?}", root, name, path);
31+
None
32+
}
33+
}
1934
pub fn try_new() -> Option<MidiSynth> {
2035
fluidlite::Settings::new()
2136
.and_then(fluidlite::Synth::new)
22-
.and_then(|synth| synth.sfload("assets/sblive.sf2", true).map(|_| synth))
37+
.and_then(|synth| {
38+
let mut path = None;
39+
if let Ok(root) = std::env::current_exe() {
40+
if let Some(root) = root.parent() {
41+
path = Self::check_path(root.to_path_buf(), Self::SOUND_FONT);
42+
}
43+
}
44+
if path.is_none() {
45+
if let Ok(root) = std::env::current_dir() {
46+
path = Self::check_path(root, Self::SOUND_FONT);
47+
}
48+
}
49+
match path {
50+
Some(path) => {
51+
println!("MidiSynth try_new() Loading: {:?}", path);
52+
synth.sfload(path, true).map(|_| synth)
53+
},
54+
None => {
55+
let path = format!("assets/{}.sf2", Self::SOUND_FONT);
56+
synth.sfload(path, true).map(|_| synth)
57+
}
58+
}
59+
})
2360
.map(Self::new)
2461
.map_err(|err| {
2562
println!("MidiSynth try_new() failed: {:?}", err);

crates/notation_model/src/play/play_clock.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,4 @@ impl PlayClock {
3030
pub fn delta_seconds(&self) -> f32 {
3131
self.delta.as_secs_f32()
3232
}
33-
pub fn get_now() {
34-
StdInstant::now();
35-
}
3633
}

0 commit comments

Comments
 (0)