The Official Raspberry Pi Projects Book - Projects_Book_v4

(singke) #1

CREATING THE


CUSTOM INTERFACE


>STEP-01
Installing the editor
First, download the free TouchOSC editor. There are
versions for macOS and Windows, and a Linux version
which will run on the Raspberry Pi. Download the ZIP
file by going to magpi.cc/2mPqfsz. Unzip it using the
Archiver tool under Accessories in the main menu.
You’ll find a file called TouchOSCEditor.jar. Move it into
your project directory. To run the editor, navigate to the
folder from a Terminal window and type:
java -jar TouchOSCEditor.jar

>STEP-02
Setting up the faders
Select the name of your device from the Size option,
and set the orientation to Horizontal. Now right-click
in the layout window and select ‘H fader’. You might be
surprised to see a vertical fader, but this is because you
have selected the horizontal orientation for the screen.
Resize this fader so that it is 50 by 415 and place it at
coordinates 872, 89. Select the colour as green and the
range from 0 to -380. Now create two V faders, resize
them to 530 by 50, and set the range to -240 to 900.
Then put fader 2 at the x/y location 34, 61 and make it
yellow, and fader 3 at 34, 462 and make it orange.

Tutorial


raspberrypi.org/magpi The Official Raspberry Pi Projects Book 143


DIY CUT-OUT THEATRE


OSC messages
Each OSC message consists of two parts: an address and
a payload. The address part is identical to the path of a
file on the Pi, the only difference being that there are
no directories, and you can build your own hierarchical
structure to suit your own needs. On TouchOSC, each
window can have a number of tabs, each tab bringing
up a different screen. The first default hierarchical
level is the tab number, preceded by a forward slash.
There is only one screen for this project so all messages
start with /1. The next level defines the control device,
so a fader might have the address /1/fader1, or a push
button /1/push4. That is as far down the hierarchy as
we need to go for this project, but you can go further if
you need to. The payload is the data that is delivered
to that address, and can be in the form of an integer, a
floating point number, text, or a Boolean logic value.
When you send a message, you have to specify both the
address and the payload.
At the receiving end, the message address is
normally parsed to see how to apply this number to
the program you want to control. In our application,
the payload will be used to move graphics around
on the screen. You can send messages back to the
TouchOSC controller, where they can be used to
change the controls without user intervention, or to
add feedback or acknowledgement of commands.


Implementation
We did hope to implement the OSC messages
in Python, as there are a few libraries to do this.
Unfortunately this proved impossible, because the
ones we tried had poor documentation that was out
of date, and either fell over when trying to cope with
three faders, or required complex multithreading
programming with no practical examples available
online. Instead, we turned to Processing, which has
a simple and reliable interface for incoming OSC
messages. We used Processing in the Ribbons project


Language
>PROCESSING

DOWNLOAD:
magpi.cc/1NqJjmV

PROJECT
VIDEOS
Check out Mike’s
Bakery videos at:
magpi.cc/1NqJnTz
Free download pdf