June 1, 2009

iphone game goodness

Filed under: Uncategorized — aturley @ 7:42 pm

I wrote a little iPhone game based on some of the same principles that I used in the TUIO system I blogged about earlier. In this system, users go to a URL to download a controller, which they then use to control spaceships (little circles on the computer screen). The game itself is hosted on a computer that is running a special web server and the game software. You can download the source for everything here.

If you were at Maker Faire and played the game at my booth, thanks for being a beta tester. Sorry if I crashed your browser.

UPDATE: If you’re coming from the MacWorld slideshow, thanks for stopping by. If you tried to play the game at Maker Faire and had trouble using the system, I apologize. Thanks to everybody who had the patience to get on the network and try out the game.

May 12, 2009

network MIDI link using ChucK and OSC

Filed under: Uncategorized — aturley @ 8:58 pm

Every once in a while I run across a blog post or a comment somewhere about how somebody wants to send a MIDI message from one computer to another. Maybe they have a keyboard that they have hooked up to one computer and they want to use it to control somebody else’s Live session. Or maybe they have some windows software that spits out MIDI, and they want to use it with some Mac software that understands MIDI.

So, let’s say you want a cross-platform solution (since if you’re only using Macs then this ships with the operating system), and you want it for free, and maybe you want it to be fairly easy to change the way the system works in case you want to try to do something weird later on down the road. To that end, I’ve written a MIDI-OSC-MIDI bridge, which you can download here. It is actually two programs, a sender and a receiver, and they use Open Sound Control to communicate. To use it, you have to install a programming language/environment called ChucK. You will probably also want to have some MIDI loopback devices set up. In OS X, you can use the Audio MIDI Setup utility to add virtual MIDI ports by selecting “IAC Driver” and adding ports. In Windows you will have to use a program like MIDI Yoke.

Go ahead and install Chuck and set up some MIDI loopback devices if you haven’t already. I’ll wait.

Now that you have ChucK installed, create two files. Let’s call the first one miditoosc.ck. It will look like this:

if (me.args() != 3) {
  <<<"usage: chuck miditoosc.ck:HOST:PORT:MIDIDEVICE">>>;
  me.exit();
 }

me.arg(0) => string host;
me.arg(1) => Std.atoi => int port;
me.arg(2) => Std.atoi => int dev;

MidiIn min;
if (!min.open(dev)) {
  <<<"Could not open MIDI device " + dev>>>;
  me.exit();
 }
MidiMsg msg;

OscSend send;
send.setHost(host, port);

while(min => now) {
  while(min.recv(msg)) {
    send.startMsg("/midi/raw", "iii");
    msg.data1 => send.addInt;
    msg.data2 => send.addInt;
    msg.data3 => send.addInt;
  }
 }

Let’s call the second one osctomidi.ck. It will look like this:

if (me.args() != 2) {
  <<<"usage: chuck osctomidi.ck:PORT:MIDIDEVICE">>>;
  me.exit();
 }

me.arg(0) => Std.atoi => int port;
me.arg(1) => Std.atoi => int dev;

OscRecv recv;
port => recv.port;
recv.event("/midi/raw, iii") @=> OscEvent oe;
recv.listen();

MidiOut mout;
if (!mout.open(dev)) {
  <<<"Could not open MIDI device " + dev>>>;
  me.exit();
 }
MidiMsg msg;

while (oe => now) {
  while(oe.nextMsg() != 0) {
    oe.getInt() => msg.data1;
    oe.getInt() => msg.data2;
    oe.getInt() => msg.data3;
    mout.send(msg);
  }
 }

The first program waits for a MIDI message. When it receives a MIDI message, it will take the data from the message, put it into an OSC message, and send the message. The second program reverses this process, waiting for an OSC message, putting the data into a MIDI message, and sending that message out to a MIDI port.

To use these programs, place the files on two computers that both have ChucK installed. Then, run the following command on both computers:

chuck --probe

This will display a list of the computer’s audio and MIDI interfaces. On my computer I see something like this:

[chuck]: ——( chuck — 2 MIDI inputs )——
[chuck]: [0] : “IAC Driver Bus 1″
[chuck]: [1] : “IAC Driver IAC Bus 2″
[chuck]:
[chuck]: ——( chuck — 2 MIDI outputs )—–
[chuck]: [0] : “IAC Driver Bus 1″
[chuck]: [1] : “IAC Driver IAC Bus 2″
[chuck]:

This tells me that there are two MIDI inputs (numbered 0 and 1) and two MIDI outputs (numbered 0 and 1). If I wanted to run osctomidi.ck and have it listen for OSC messages on port 6969 and send MIDI messages to the output called “IAC Driver Bus1″, I would run the following command from the directory that contained the file osctomidi.ck:

chuck osctomidi.ck:0:6969

If you didn’t already know, arguments are passed to Chuck processes by separating them with colons. The first argument is the device number (0) and the second argument is the port (6969). To run miditoosc.ck, I would use a similar command:

chuck miditoosc.ck:127.0.0.1:1:6969

In this case the first argument is the host to which I want to send the OSC messages (I’m just sending to the local host here), the next argument is the device number, and the final argument is the port. If both of these programs are running and the host named in the second command is the host where the first command is run, then you should have a link between the two computers (or, in this case, one computer) that will connect the MIDI input from the second host to the MIDI output on the first host.

Just a note: If you are doing this all on one computer you may see a message that says something like “cannot bind to tcp port 8888″. You can safely ignore that message.

I’ve defined an OSC message here that looks like this:

/midi/raw [data1] [data2] [data3]

where data1, data2, and data3 are integers. These integers are just the data that would normally make up a MIDI triplet. I’ve used the message address “/midi/raw” because it might make sense at some later point to have different OSC messages for different types of MIDI messages. For example, I might use something like this for MIDI CC messages:

/midi/cc [control] [value] [channel]

But for now I want to remain message-type agnostic.

Since these programs use OSC they can provide a bridge between MIDI and environments that may support OSC more easily than MIDI. For example, there are a number of OSC packages for Python that are easy to use, but MIDI libraries seem to be fairly platform-specific. Or there is the case of Java on the Mac, which does not support the standard Java MIDI libraries.

So there you have it. ChucK, OSC, and MIDI, working together.

April 21, 2009

quick little hacks with PD and OSC

Filed under: Uncategorized — aturley @ 8:53 pm
a little PD and OSC hack

a little PD and OSC hack

This is a little PD hack that lets you set a value using an OSC message. The OSC message comes in on port 5678, and has the following form:

/cmd [receiver] [value]

where “[receiver]” is the name of the receiver, and “[value]” is the new value. The unpack and repack are necessary to convert the first argument into a symbol.

If you have Python and the simpleosc library, you can set the value connected to “jesus” to 10 like this:

>>> import osc
>>> osc.init()
>>> osc.sendMsg("/cmd", ["jesus", 10], “127.0.0.1″, 5678)

April 18, 2009

touchy feely

Filed under: Uncategorized — aturley @ 12:50 am

A little while back Apple rejected an iPhone app that would have let you use your iPhone as a TUIO controller. There was a big discussion about the whole thing over at CreateDigitalMusic, with some people supporting Apple’s decision and others decrying it. Most of those who supported Apple seemed to feel that it was their store and they could damned well sell whatever they wanted. I tend to agree with this sentiment, but I still think that it would be nice to have a way to get an app onto the iPhone without having to get Apple’s permission.

At about the same time the discussion was taking place over at CDM, I was playing with a program called OSCemote on my brand new iPhone. OSCemote lets you create interfaces for your iPhone that can send and receive OSC messages. Interfaces are created as HTML documents, with snippets of Javascript doing the work of monitoring elements on the page and sending the messages. I began to wonder how hard it would be to use web app running in Safari as a multitouch interface.

I’ve been playing around with these ideas for the last month or so, and tonight I decided to go back to the issue that got me going on this train of thought. I took a look at the TUIO protocol and took a swing at creating a web app that would talk to a web server that would in turn send TUIO messages to other programs. I’m not sure I got all the details of TUIO right, but I think I have a workable first pass at something.

I’ve packaged the system up, and you can download it here. You’ll need Python to run the web server. If you have a Mac then you already have Python. Users of other operating systems may have to install it if it isn’t already there. You will also need some sort of program that can do something with the data. I’ve just been dumping it to a Pure Data patch. And you’ll need an iPhone or an iPhone simulator.

UPDATE (4/20/2009): The link now links to the new version which uses the 2Dcur profile instead of the 2Dobj profile. Thanks to Martin Kaltenbrunner for pointing this out.

April 9, 2009

Maker Fair(e) 2009

Filed under: Uncategorized — aturley @ 4:50 pm

Last year Tim, Mike and I built some big LED panels for Tim’s band Microfiche. Tim is a graphic/industrial designer, Mike is an electrical engineer, and I’m a programmer, and the project was a great way for us to bring all of our skills together to create something cool. Here’s some pictures of us (and some dear friends) during the build phase:
Those kids, with the soldering and the cutting.
Andy, Ben, and Mike keep it real.
Tim keeps it even realer.
And in this video you can see one of the panels during a show:

While we were working on the project we started to call ourselves Tricerabot, and the name stuck. This year we aim to have a Tricerabot booth at Maker Faire. Mike will have some new versions of his shifters with microcontrolled LEDs putting on light shows. Tim will have some of his new illustrations and designs (he does the Tricks of the Trade comic strip which appears monthly in Make Magazine). I might have some new interactive goodies (maybe some games or something).

And we’re working on a collaborative project to highlight the way our strengths complement each other. One plan is to use some wireless microcontroller boards to set up a proximity detection system. The system will be able to detect how far we are from the booth, and this information will be used to control a projected image. We talked about the image representing each of us as a different colored square that moves along an path, with the paths intersecting in the the middle. As the squares get closer and overlap, new images will emerge. Here’s a mock up of what we’re talking about:
tricerabot_colors

See you in San Mateo!

January 29, 2009

songsmith again

Filed under: Uncategorized — aturley @ 3:14 pm

In the novel Dirk Gently’s Holistic Detective Agency, one of the characters has created a spreadsheet that sets data to music. Thanks to Songsmith, we’re more or less there now.

I suppose it’s only a matter of time before Microsoft realizes that the best use for their new toy is as a chart type in Excel.

January 22, 2009

songsmith destroys the universe and rebuilds it

Filed under: Uncategorized — aturley @ 9:33 am

Microsoft recently released Songsmith, software that takes a vocal performance and generates a musical score.

The original intention, as I understand it, was to give singers (or people who fancied themselves as such) an easy way to put some music around their songs. Ah, but the law of unintended consequences had other ideas.

What Microsoft has done is opened a rift between our universe and some sort of parallel universe where all the songs we know were actually a collaboration between a songwriter and a bunch of mediocre musicians with Casio synths. A part of me is afraid that this rift will eventually annihilate our own universe. The only way to stop the onslaught is by embracing a new, un-Songsmithable aesthetic.

But I don’t know if I want it to end. I’m really enjoying going to YouTube every day and finding new songs. And as someone with at least a passing interest in the intersection of computers and the arts, I’m at least sort of impressed with what Microsoft has done technologically.

As a final thought, I hypothesize that there is some sort of identity relationship between MIA and Songsmith, whereby feeding Songsmith an MIA song will actually produce the same song.

Or maybe, just maybe, the awesomeness is amplified into this:

January 18, 2009

A few notes on installing oscpack in OS X

Filed under: Uncategorized — aturley @ 11:50 am

I want to play around with ARToolKit. My plan is to take the pattern detection information and ship it off to places for further processing. I figured the easiest way to do that would be to use Open Sound Control. Since ARToolKit is a C framework, I though it would make sense to use an OSC library written in C. oscpack looked like a good candidate.

I’m using a Intel-based Mac. To build and install the oscpack library I needed make a few changes to the Makefile. I thought I would share these changes in case anybody else tries to do this.

Step zero is ONLY NECESSARY IF YOU ARE RUNNING ON A POWER PC-BASED MAC. Sorry to shout, I just want to emphasize this. I didn’t need to do this, but I’m pointing it out anyway in case it helps somebody. At the beginning of the Makefile, change

ENDIANESS=OSC_HOST_LITTLE_ENDIAN

to

ENDIANESS=OSC_HOST_BIG_ENDIAN

This next step, step one, is only necessary if you don’t want to create (or have not already created) a /usr/local directory. It doesn’t exist by default, and if it isn’t there then the installation process will fail. You need to change

PREFIX = /usr/local

to

PREFIX = /usr

The thrid step involves using the right compiler syntax to set up a shared library. Change this part of the code

@#GNU/Linux case
$(CXX) -shared -Wl,-soname,$(LIBSONAME) -o $(LIBFILENAME) $(LIBOBJECTS) -lc
@#Mac OS X case
@#$(CXX) -dynamiclib -Wl,-install_name,$(LIBSONAME) -o $(LIBFILENAME) $(LIBOBJECTS) -lc

to

@#GNU/Linux case
@#$(CXX) -shared -Wl,-soname,$(LIBSONAME) -o $(LIBFILENAME) $(LIBOBJECTS) -lc
@#Mac OS X case
$(CXX) -dynamiclib -Wl,-install_name,$(LIBSONAME) -o $(LIBFILENAME) $(LIBOBJECTS) -lc

Now you can run sudo make install and the libraries and headers will be installed on your system. Awesome! Now try to build one of the examples, like examples/SimpleSend.cpp. Don’t forget to point to the include files (-I) and the shared library (-l).

cd examples
g++ I/usr/lib/oscpack -loscpack -o SimpleSend SimpleSend.cpp

Now if you listen to port 7000 and run the program you should see the message.

November 25, 2008

calculator music

Filed under: Uncategorized — aturley @ 10:17 pm

A while back, there was a poll on createdigitalmusic.com where people were asked about mobile music making devices that they would like to see the website cover. A few people said that they wanted to see coverage of calculators. It was treated as a joke, but I thought it might be fun to make it a reality.

I have an HP 48 GX. The HP 48 actually has a speaker that can be controlled programatically. This is fun for little beeps, but it isn’t very flexible. The calculator also has a serial port. This seemed more promising. I decided to try to figure out a way to convert the signal from the serial port into MIDI messages that could then be sent to a MIDI keyboard.

I used a Parallax Basic Stamp to read serial data on one pin and send MIDI data on another pin. Stamp Basic provides some nice functions for reading and writing serial data. The code on the Stamp looks like this:

note var byte
velocity var byte
MIDINOTEON con 144
MIDINOTEOFF CON 128
MIDICHANNEL CON 0
MIDIVELOCITY CON 127
MAINLOOP:
SERIN 3, 167, 16780, [note, velocity]
SEROUT 4, 12, [MIDINOTEON + MIDICHANNEL, note, velocity]
GOTO MAINLOOP

Nothing too special here. We read the data in on pin 3, and write out on pin 4. The incoming serial data needs to be coming in at 2400 baud. Also, the incoming message only specifies the note and velocity. The output should go through a MIDI output circuit.

I wrote some code on the calculator that takes keystrokes and turns them into MIDI noteon messages. The code is broken into two functions. The first is called FLIP. It takes a list and an index into the list, and returns the list with a “not” applied to the value at the given index, as well as the original index and the new value. I use this function along with a list to keep track of whether a note is on or off, so that when the key is pressed the corresponding note can be turned on or off. Here’s the code for FLIP:

<< -> L P << L P GET NOT DUP L SWAP P SWAP PUT P ROT >> >>

You caught all that, right? And now, here’s the code that watches for a keypress and sends the appropriate message:

<< '0*X' 'X' 0 127 1 SEQ
WHILE 1 REPEAT
IF KEY THEN
1 - DUP 10 / FLOOR 6 * 40 + SWAP 10 MOD + FLIP 64 * MIDIOUT
END
END >>

Ah, right, and the MIDIOUT function:


<< CHR SWAP CHR SWAP XMIT DROP >>

All of this is really just a fancy way to use the built-in XMIT function to send two bytes out the serial port.

So, after the coding and the circuit building, here’s what I got.

May 5, 2008

microfiche machine

Filed under: maker faire 2008 — aturley @ 8:18 pm

I had the microfiche machine at Maker Faire. And I said that I would post some information about it here, so that’s what I’ll do.

The microfiche machine takes light (in this case, from the screen of the microfiche reader) and converts it into MIDI signals that can then be sent to devices that take MIDI input, like synthesizers or computers. We use a phototransistor on the end of an antenna to read the light level from the screen. That information is then processed by a BS2 and converted into a MIDI signal.

In addition to the phototransistor, the microfiche machine has several other inputs.

  • two dials and a button to set the highest and lowest note played
  • a stop/star button that stops and starts the MIDI signals without actually turning the machine off
  • two buttons that are used to calibrate the highest and lowest light signals
  • a dial that is used to set the key of the notes that will be played

The BS2 does not have an analog to digital converter, but it does have a function called RCTIME that can be used to detect changes in resistance by determining the time it takes for an RC (resistor-capacitor) circuit to change its voltage. This article talks about how to use the RCTIME fuction and how to construct circuits that can use it. I use the function to measure the light levels from the phototransistor, and to measure the settings of the dials, which are just potentiometers (variable resistors).
Here is the BS2 source code that I use. If you have any questions, feel free to post them.

Update: The IEEE Spectrum website has a little writeup and a video showing the microfiche machine in action.

Next Page »

Powered by WordPress

On this site: