You are here: Home Documentation How-tos Create Your Own OSC subsystem
Document Actions

Create Your Own OSC subsystem


This How-to is intended for: Microcontroller Developers

Create a custom OSC interface to your own Make Controller program.

Problem

You're writing some code for the Make Controller, and you want to be able to interact with it via OSC.


Solution

Writing your own subsystem is fairly straight forward thanks to the existence of several Osc helpers.  Check there API documentation here.  There are a couple different kinds of helpers:

As an example, I'll include the steps for creating a fictional GPS system.  It's a good idea to adhere to the existing naming convention for your functions, although obviously not necessary. 

The steps to setting up your subsystem are:

  1. Name your new subsystem. 
    static char* MyGPSOsc_Name = "gps";
  2. Name the properties that your subsystem will support.
    static char* MyGPSOsc_PropertyNames[] = { "latitude", "longitude", 0 }; // must end with a zero
  3. Define getters and setters for each of those properties and functions to call them by property index.
    int MyGPSOsc_PropertySet( int index, int property, int value )   
    {
    // it doesn't make sense to write values to the latitude and longitude properties
    // so we don't have anything here
        return CONTROLLER_OK;
      }

      int MyGPSOsc_PropertyGet( int index, int property )
      {
        int value;
         switch ( property )
         {
          case 0: // latitude in our list of properties above
            value = MyGPS_GetLatitude( index );
            break;
          case 1: // longitude in our list of properties above
            value = MyGPS_GetLongitude( index );
            break;
        }
        return value;
      }
  4. Implement a function to call the correct helper when Osc calls you.
     // this is called when the OSC system determines an incoming message is for you.
    int MyGPSOsc_ReceiveMessage( int channel, char* message, int length )
    {  
        return Osc_IntReceiverHelper( channel, message, length,
                                            MyGPSOsc_Name,
                                            MyGPSOsc_PropertySet,
                                            MyGPSOsc_PropertyGet,
                                            MyGPSOsc_PropertyNames );
       }
  5. Finally, add your subsystem to the list that Osc maintains.  This is typically done in the Run( ) routine in make.c that gets called on startup. 
    void Run( ) // this task gets called as soon as we boot up.
    {
    // other startup stuff
    Osc_RegisterSubsystem( MyGPSOsc_GetName(), MyGPSOsc_ReceiveMessage, NULL );
    }

Discussion

If you create your own useful subsystem, please share!