Skip to content

medokin/soundpad-connector

Repository files navigation

Logo SoundpadConnector .NET

SoundpadConnector provides an .NET API to programmatically interact with a local Soundpad instance.

Table of contents

Requirements

This library is build on .NET Standard 2.0. Following plattforms are supported:

  • .NET Core 2.0 or higher
  • .NET Framework 4.6.1 or higher

Installation

Get the NuGet package SoundpadConnector or install via NuGet console:

PM> Install-Package SoundpadConnector

QuickStart

using System;
using SoundpadConnector;

namespace Examples {
    class Program {
        public static Soundpad Soundpad;

        static void Main(string[] args)
        {
            Soundpad = new Soundpad();
            Soundpad.StatusChanged += SoundpadOnStatusChanged;

            // Note that the API is asynchronous. Make sure that Soundpad is connected before executing commands.
            Soundpad.ConnectAsync();

            Console.ReadLine();

        }

        private static void SoundpadOnStatusChanged(object sender, EventArgs e)
        {
            Console.WriteLine(Soundpad.ConnectionStatus);

            if (Soundpad.ConnectionStatus == ConnectionStatus.Connected)
            {
                Soundpad.PlaySound(1);              
            }
        }
    }
}

Documentation

Api docs

Read the Docs online. This is still work-in-progress!

Build the docs

  1. Install Chocolatey
  2. Install Docfx via Chocolatey choco install docfx -y
  3. Run docfx docfx/docfx.json in project root
  4. Browse the output in /docs

Examples

Browse the Examples.

Limitations

  • SoundpadConnector does not work with Soundpad's Demo version 3 and below.
  • UWP is not supported/tested. The sandbox refuses pipe connections. Users reported that it works from Windows 10 version 2004 and above.

Troubleshooting

Unexpected result when performing multiple calls?

Soundpad calls are not transactional. You may get a response before the action happens in Soundpad. For example:

var countResult = await soundpad.GetSoundFileCount();
Console.WriteLine(countResult.Value); // 9

await soundpad.AddSound(newSoundPath);

var newCountResult = await soundpad.GetSoundFileCount();
Console.WriteLine(newCountResult.Value); // 9 again, but we're expecting 10, right?

You can wait a certain amount of time between the calls, but that won't be safe either and makes your app slow. Another way is to loop until the value changes:

var countResult = await soundpad.GetSoundFileCount();
Console.WriteLine(countResult.Value); // 9

await soundpad.AddSound(newSoundPath);

while(true) {
    var newCountResult = await soundpad.GetSoundFileCount();
    
    if(newCountResult.Value == countResult.Value) {
        Console.WriteLine(newCountResult.Value); // 10
        break;
    }
}

Contributing

You may contribute in several ways like creating new features, fixing bugs, improving documentation and examples or translating any document here to your language. Read our Code of Conduct.

License

MIT - Nikodem Jaworski - 2018

Special thanks

  • Leppsoft - The Company behind Soundpad