What you need

1. Processing

Processing is a java-based programming language and development environment for visual applications. Download Processing.

2. The Processing Lemma

Download the Lemma Library and example sketches.

3. Libraries added to the Processing IDE

Add the lemma folder to your Processing libraries directory; for Mac users this is located in ~/Documents/Processing/Libraries. Restart Processing.

4. Review the Lemma Examples

You can find a few example sketches in Processing under File -> Examples then Contributed Libraries -> lemma

Using the Processing Lemma

Dependencies

Import core Lemma, Event, and EventHandler libraries.

import lemma.library.Event;  
import lemma.library.EventHandler;  
import lemma.library.Lemma;

Instantiate a Lemma

Lemma lemma;

Initialize a Lemma

Inside your setup function, initialize the lemma. guestName is the ID Noam Hosts will associate with your application. If roomName is left blank, the lemma is a Free Guest and may be grabbed by any Host via the Host Interface. Otherwise, it will only join a host with the specified roomName.

void setup(){
  lemma = new Lemma(this, <guestName>, <roomName>);
}

‘Level.FINE’ is an optional key that will add debug output to the Processing console.

lemma = new Lemma(this, <guestName>, <roomName>, Level.FINE);

Hear Messages

Add one or more listeners inside your setup function.

lemma.hear(<topicName>, new <MyEventHandler>())

Extend the EventHandler interface defining a callback(Event event) method to handle callbacks for each listener.

class <MyEventHandler> implements EventHandler {
  public void callback(Event event){
    // handle event ... e.g. [Event.name / Event.stringValue / Event.intValue / Event.floatValue]
    // see the lemma_runAllTypes example for details.
  }
}

Run the Lemma

Within the draw loop, run the lemma.

void draw(){
  lemma.run();
}

Speak Messages

From your application, speak a message. topicName is the Topic

lemma.sendEvent( <topicName>, <messageValue> );

Examples

###Hearing messages
Instantiate, initialize, and run a lemma called “Processing Lemma” that joins room “Test Room”. Registers to hear messages on topic “Speed” and prints the value to the console.

import lemma.library.Event;
import lemma.library.EventHandler;
import lemma.library.Lemma;

Lemma lemma; //instantiate the lemma

void setup(){
  lemma = new Lemma(this, "Processing Lemma", "Test Room"); //initialize lemma
  lemma.hear("Speed", new SpeedHandler()); //register for messages on topic Speed
}
void draw(){
  lemma.run(); //listen for new Noam messages.
}

class SpeedHandler implements EventHandler {
  public void callback(Event event){
      System.out.println("Caught event : " + event.name + " : " + event.doubleValue); //print message value
  }
}

Speaking messages

Instantiate, initialize, and run a lemma called “Processing Lemma” that joins room “Test Room”. Registers to speak string messages on topic “messageString” and prints the value to the debugger.

import lemma.library.Event;
import lemma.library.EventHandler;
import lemma.library.Lemma;

String messageString = "Hello";
int lastSecond = second();
Lemma lemma; //instantiate the lemma

void setup(){
  lemma = new Lemma(this, "Processing Lemma", "Test Room"); //initialize lemma
}
void draw(){
  int currSecond = second();

  // Send a message every second
  if(lastSecond != currSecond){
    lastSecond = currSecond;
    if ( lemma.sendEvent("messageString", messageString) ){
      //alternate sending "Hello" and "World"
      messageString = (messageString == "Hello") ? "World" : "Hello";
    }
  }
  lemma.run(); //listen for new Noam messages.
}

Limitations

• Passing maps and nested objects with Processing is not clean yet. Improvements and tutorials coming soon.

Developers

If you’re interested in checking out the source or contributing to this Lemma, visit our GitHub repository.