Giter Club home page Giter Club logo

fluidlite-rs's Introduction

Rust fluidlite bindings

github crate docs LGPL-2.1 CI

This project aims provide safe Rust bindings to fluidlite C library.

FluidLite is a very light version of FluidSynth designed to be hardware, platform and external dependency independant. It only uses standard C libraries.

It also adds support for SF3 files (SF2 files compressed with ogg vorbis) and an additional setting to remove the constraint of channel 9 (drums): fluid_settings_setstr(settings, "synth.drums-channel.active", "no"); you can still select bank 128 on any channel to use drum kits.

FluidLite keeps very minimal functionnalities (settings and synth), therefore MIDI file reading, realtime MIDI events and audio output must be implemented externally.

Crates

Features

  • bindgen Force generate bindings itself instead of use pre-generated
  • builtin Force compile builtin fluidlite C-library
  • pkg-config Use pkg-config to find installed libraries
  • with-sf3 Enable SoundFont3 support (SF2 with vorbis-encoded samples)
  • with-stb Use stb-vorbis decoder instead of libvorbis/libogg.
  • shared Build shared fluidlite C-library
  • static Build static fluidlite C-library

When pkg-config feature is used the installed fluidlite library will be used if found. To force build and link builtin version you can use builtin feature.

Example

use std::{fs::File, io::Write};
use byte_slice_cast::AsByteSlice;
use fluidlite::{Settings, Synth};

let settings = Settings::new().unwrap();

let synth = Synth::new(settings).unwrap();
synth.sfload("sf_/Boomwhacker.sf3", true).unwrap();

let mut buffer = [0i16; 44100 * 2];
let mut file = File::create("soundfont-sample.pcm").unwrap();

synth.note_on(0, 60, 127).unwrap();
synth.write(buffer.as_mut()).unwrap();
file.write(buffer.as_byte_slice()).unwrap();

synth.note_off(0, 60).unwrap();
synth.write(buffer.as_mut()).unwrap();
file.write(buffer.as_byte_slice()).unwrap();

fluidlite-rs's People

Contributors

hfiguiere avatar jf2048 avatar katyo avatar woyten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

fluidlite-rs's Issues

FluidLite is not used

Hi, thanks for the great bindings library!

FluidSynth works without any problems. However, I have a problem / question: If I understand the documentation correctly the "builtin" feature should replace FluidSynth with FluidLite. But when I use features = ["builitin"] it still seems to use FluidSynth.

For example, I get the error message "No tuning at bank 0, prog 0". The error message is expected but it cannot see it being declared in FluidLite s.t. I suspect it comes from FluidSynth.

feature_request: add method for fluid_synth_all_notes_off

Fluidlite exposes a function for turning all notes off:

// In fluid_synth.c
/*
 * fluid_synth_all_notes_off
 *
 * put all notes on this channel into released state.
 */
int
fluid_synth_all_notes_off(fluid_synth_t* synth, int chan)
{ /* ... */ }

It doesn't seem that there's any method on fluidlite::Synth for this, can we add it?

I sort of need it for my MIDI player (plmidi).

Specify MSRV in README.md

Due to the crate requiring a very recent compiler, 1.54, to compile, this should be pointed out in the README.md to prevent any confusion.
Thank you.

does not link

hi, i'm trying your crate (seems nice btw) but I cannot get it to compile.

what's strange is that I cloned your repo and all tests pass. I also tried this code: https://github.com/Woyten/tune/tree/master/microwave which compiles fine.

however if i copy paste the example from the doc in a main fn it compiles but does not link.

I think it is not linking agains fluidsynth.

i'm not sure why other projects get the right -L flag or what i should do to get it.

─wagnerf@grou /run/user/1000/foo ‹master*›
╰─➤ cargo run --verbose 101 ↵
Fresh unicode-xid v0.2.1
Fresh autocfg v1.0.1
Fresh byte-slice-cast v1.0.0
Fresh proc-macro2 v1.0.24
Fresh quote v1.0.7
Fresh bitflags v1.2.1
Fresh fluidlite-sys v0.1.3
Fresh syn v1.0.54
Fresh num-traits v0.2.14
Fresh num-derive v0.3.3
Fresh fluidlite v0.1.3
Compiling foo v0.1.0 (/run/user/1000/foo)
Running rustc --crate-name foo --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=224befcf6994fbcb -C extra-filename=-224befcf6994fbcb --out-dir /run/user/1000/foo/target/debug/deps -C incremental=/run/user/1000/foo/target/debug/incremental -L dependency=/run/user/1000/foo/target/debug/deps --extern byte_slice_cast=/run/user/1000/foo/target/debug/deps/libbyte_slice_cast-5254c372e970eb42.rlib --extern fluidlite=/run/user/1000/foo/target/debug/deps/libfluidlite-a01d1e249cca28e3.rlib
error: linking with cc failed: exit code: 1
|
= note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-Wl,--eh-frame-hdr" "-L" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.1gdapcfyd9myvsvh.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.1nsyrpr5gq1hxypp.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.1nw0yc0zwdvtesem.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.1ohxct1ueqt9pmxw.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.1zv5edazuhw0jm1x.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.24puxivzo5gr1sr7.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.2kgi06j44vctx977.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.2smqm7932xge1ym9.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.2zniwwsq1qbmiaer.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.2zwxo4g3jp3lbwyk.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.38f1mf1ortih5tp2.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.3apql0f8tttfyh40.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.3m73wyt5kwtjdihb.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.439gltnjmy9bphi1.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.4ge9o8my3nptz9i4.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.4lk0ynvv9gy1r2sf.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.4n7yyov6sx4ap8ys.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.560rk7fyfl9gs7vd.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.65idyixl406yheq.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.7bmbiy77pmt1giu.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.a5fsnbrz7te6fiy.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.fhz4vs9kwrmsohr.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.izf4xq5tzrembtv.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.mf5qlnsnufw1yrn.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.ocjdx2s17ckg40i.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.v767y6xvbea4ara.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.xzpm0vyqkd1nwjc.rcgu.o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.yhf25m53dnzpbh7.rcgu.o" "-o" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb" "/run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.3mbuipu43109e8ck.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/run/user/1000/foo/target/debug/deps" "-L" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/run/user/1000/foo/target/debug/deps/libfluidlite-a01d1e249cca28e3.rlib" "/run/user/1000/foo/target/debug/deps/libfluidlite_sys-43c8c5211bb3382d.rlib" "/run/user/1000/foo/target/debug/deps/libnum_traits-ec7a39eee29a6869.rlib" "/run/user/1000/foo/target/debug/deps/libbitflags-385fd203704f77c6.rlib" "/run/user/1000/foo/target/debug/deps/libbyte_slice_cast-5254c372e970eb42.rlib" "-Wl,--start-group" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-93cbfed54dd1bac8.rlib" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-db33fe383d9e671a.rlib" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-4afe0e223ea50f9d.rlib" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-76d88ad8c833f039.rlib" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-762cea37cccf8abe.rlib" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-8de1e75656157df8.rlib" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-76f54e5a49eca8e8.rlib" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-d7aed80bcad8813a.rlib" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-a3916e8afa60a160.rlib" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-eaacce9b176ef080.rlib" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-81e497cd060f0dda.rlib" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-949464f6d582f46f.rlib" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-1ffc094785c92121.rlib" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-f19c324859e53f08.rlib" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-0b82195f1020bf42.rlib" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-4f2339b0071e1016.rlib" "-Wl,--end-group" "/home/wagnerf/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-774a5f30b27a1f9c.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-ldl" "-lutil"
= note: /nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /run/user/1000/foo/target/debug/deps/foo-224befcf6994fbcb.xzpm0vyqkd1nwjc.rcgu.o: in function fluidlite::synth::font::<impl fluidlite::synth::Synth>::sfload': /home/wagnerf/.cargo/registry/src/github.com-1ecc6299db9ec823/fluidlite-0.1.3/src/synth/font.rs:20: undefined reference to fluid_synth_sfload'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /run/user/1000/foo/target/debug/deps/libfluidlite-a01d1e249cca28e3.rlib(fluidlite-a01d1e249cca28e3.fluidlite.c55rvgws-cgu.0.rcgu.o): in function fluidlite::synth::midi::<impl fluidlite::synth::Synth>::note_on': /home/wagnerf/.cargo/registry/src/github.com-1ecc6299db9ec823/fluidlite-0.1.3/src/synth/midi.rs:12: undefined reference to fluid_synth_noteon'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /run/user/1000/foo/target/debug/deps/libfluidlite-a01d1e249cca28e3.rlib(fluidlite-a01d1e249cca28e3.fluidlite.c55rvgws-cgu.0.rcgu.o): in function fluidlite::synth::midi::<impl fluidlite::synth::Synth>::note_off': /home/wagnerf/.cargo/registry/src/github.com-1ecc6299db9ec823/fluidlite-0.1.3/src/synth/midi.rs:19: undefined reference to fluid_synth_noteoff'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /run/user/1000/foo/target/debug/deps/libfluidlite-a01d1e249cca28e3.rlib(fluidlite-a01d1e249cca28e3.fluidlite.c55rvgws-cgu.0.rcgu.o): in function fluidlite::synth::misc::<impl fluidlite::synth::Synth>::error': /home/wagnerf/.cargo/registry/src/github.com-1ecc6299db9ec823/fluidlite-0.1.3/src/synth/misc.rs:9: undefined reference to fluid_synth_error'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /run/user/1000/foo/target/debug/deps/libfluidlite-a01d1e249cca28e3.rlib(fluidlite-a01d1e249cca28e3.fluidlite.c55rvgws-cgu.0.rcgu.o): in function fluidlite::synth::write::<impl fluidlite::synth::Synth>::write_i16': /home/wagnerf/.cargo/registry/src/github.com-1ecc6299db9ec823/fluidlite-0.1.3/src/synth/write.rs:67: undefined reference to fluid_synth_write_s16'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /run/user/1000/foo/target/debug/deps/libfluidlite-a01d1e249cca28e3.rlib(fluidlite-a01d1e249cca28e3.fluidlite.c55rvgws-cgu.0.rcgu.o): in function fluidlite::synth::Synth::new': /home/wagnerf/.cargo/registry/src/github.com-1ecc6299db9ec823/fluidlite-0.1.3/src/synth.rs:47: undefined reference to new_fluid_synth'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /run/user/1000/foo/target/debug/deps/libfluidlite-a01d1e249cca28e3.rlib(fluidlite-a01d1e249cca28e3.fluidlite.c55rvgws-cgu.0.rcgu.o): in function <fluidlite::synth::Synth as core::ops::drop::Drop>::drop': /home/wagnerf/.cargo/registry/src/github.com-1ecc6299db9ec823/fluidlite-0.1.3/src/synth.rs:70: undefined reference to fluid_synth_get_settings'
/nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /home/wagnerf/.cargo/registry/src/github.com-1ecc6299db9ec823/fluidlite-0.1.3/src/synth.rs:72: undefined reference to delete_fluid_synth' /nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /run/user/1000/foo/target/debug/deps/libfluidlite-a01d1e249cca28e3.rlib(fluidlite-a01d1e249cca28e3.fluidlite.c55rvgws-cgu.1.rcgu.o): in function <fluidlite::settings::Settings as core::ops::drop::Drop>::drop':
/home/wagnerf/.cargo/registry/src/github.com-1ecc6299db9ec823/fluidlite-0.1.3/src/settings.rs:32: undefined reference to delete_fluid_settings' /nix/store/b10shv9yqbgps47y0n8x7l7bq8fmp1i6-binutils-2.31.1/bin/ld: /run/user/1000/foo/target/debug/deps/libfluidlite-a01d1e249cca28e3.rlib(fluidlite-a01d1e249cca28e3.fluidlite.c55rvgws-cgu.1.rcgu.o): in function fluidlite::settings::Settings::new':
/home/wagnerf/.cargo/registry/src/github.com-1ecc6299db9ec823/fluidlite-0.1.3/src/settings.rs:38: undefined reference to `new_fluid_settings'
collect2: error: ld returned 1 exit status

error: aborting due to previous error

error: could not compile foo

Caused by:
process didn't exit successfully: rustc --crate-name foo --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=224befcf6994fbcb -C extra-filename=-224befcf6994fbcb --out-dir /run/user/1000/foo/target/debug/deps -C incremental=/run/user/1000/foo/target/debug/incremental -L dependency=/run/user/1000/foo/target/debug/deps --extern byte_slice_cast=/run/user/1000/foo/target/debug/deps/libbyte_slice_cast-5254c372e970eb42.rlib --extern fluidlite=/run/user/1000/foo/target/debug/deps/libfluidlite-a01d1e249cca28e3.rlib (exit code: 1)

wasm32-unknown-unknown support

Any chance that support for wasm32-unknown-unknown is arriving? Maybe this can be achieved using clang with wasm32-unknown-unknown LLVM backend?

Memory leak in test case `settings_ref`

I've been experimenting with a version of Miri that can execute foreign functions. It interprets the LLVM bytecode that is produced during a crate's build process. We're hoping our results can assist with the Krabcake project.

I ran your test cases in this tool, and it found a few memory leaks in the test settings_ref. It seems like the Drop implementation of Settings is never called, since Settings is consumed by Settings::into_ptr().

Instead, maybe Settings could spawn a SettingsRef object tied to its lifetime using a pattern like this:

impl Settings {
    pub(crate) fn as_ref(&self) -> SettingsRef<'_> {
        unsafe { SettingsRef::from_ptr(self.handle) }
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.