Code Monkey home page Code Monkey logo

sunsharp's Introduction

SunSharp

SunVox is a small, fast and powerful modular synthesizer with pattern-based sequencer (tracker). SunVox Library is the main part of the SunVox engine without a graphical interface.

SunSharp is a wrapper and helper library for SunVox Library, written in C#. The library contains a thin wrapper, allowing for comfortably making calls with C#-style methods and objects, as well as an intuitive object-oriented wrapper, managing a few more things for the user. Additionally, additional abstractions and mechanisms are provided to help implement dynamic music in games and other software.

Target SunVox version: 2.1b.

How to install

Two packages are available on NuGet:

To use the wrapper, install the SunSharp package. To get automatically managed binaries, install the SunSharp.Redistribution package. Alternatively, you may load the library and provide necessary function delegates yourself (see: SunSharp.LibraryLoading::ProxyClass and SunSharp.Redistribution::LibraryLoader).

Platforms supported by the binaries in SunSharp.Redistribution are:

  • Windows x86, x86_64;
  • Linux x86, x86_64, arm64;
  • macOS x86_64, arm64.

There is also a Unity package.

How to start

Object wrapper

After obtaining an instance of ISunVoxLib representing the loaded library, you may create an 'instance' of the engine. All library functions are grouped into objects that make sense together.

Here's an example that plays a song, then waits until it's finished:

using SunSharp.ObjectWrapper;
/* ... */
var sv = new SunVox(lib))
var slot = sv.Slots[0];
slot.Open();
slot.Load("song.sunvox");
slot.SetAutostop(true);
slot.Rewind(0);
slot.Play();
int line = 0;
while (line != slot.GetSongLengthInLines() - 1 || slot.IsPlaying())
    line = slot.GetCurrentLine();

WriteLine("Song finished");
slot.Close();
sv.Dispose();

Thin wrapper

If you wish to use the functions as provided, you may use the thin wrapper. All the calls are directly available from the ISunVoxLib interface, though using extensions provided in SunSharp.ThinWrapper namespace is advisable. The extension methods handle marshalling and other annoying boilerplate for you; the names are very similar to those in official documentation, and their usage should be very intuitive.

Remember, you will have to deal with locking/unlocking yourself!

Here's an example, equivalent to object wrapper code:

using SunSharp.ThinWrapper;
/* ... */
lib.Init(sampleRate: -1);
lib.OpenSlot(0);
lib.Load(0, "song.sunvox");
lib.SetAutostop(0, autostop: true);
lib.Rewind(0, line: 0);
lib.Play(0);
int line = 0;
while (line != lib.GetSongLengthInLines(0) - 1 || lib.IsPlaying(0))
    line = lib.GetCurrentLine(0);

lib.CloseSlot(0);
lib.Deinit();

More examples

More examples available in the Examples folder.

Bug reporting

Please use the issues page of this repository. If the problem is with the underlying library, I will pass the necessary information to the SunVox forums myself.

Questions & Answers

Can I use multiple SunVox instances?

Due to engine limitations, only one instance can be used per loaded library. Since it is possible to load multiple libraries, or versions of the same library into your process, it should be possible.

Will it work on Android/iOS/whatever?

Maybe? My code is basically a wrapper, so it should be platform invariant. If the platform in question is supported by the SunVox Library, and there is a binary provided, you should be able to load it yourself.

Is the library safe?

If you want to, you can shoot yourself in the foot, although there should be warning signs along the way. The code should be transparent enough that any unexpected behaviour should originate from SunVox itself. No promises are made, but if you don't mix thin and object wrapper code, it should be fine.

sunsharp's People

Contributors

sotakebk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.