I'll post this Python code after I wean the tone generation off of Max/MSP to ChucK. In fact, I plan to make tone generation a plug-in. I'd like to use some MIDI-driven synths, but I am up against a stop: Just Intonation implies prefixing each MIDI noteon with a pitch bend, but pitch bend affects all notes on a MIDI channel, and each note in Just Intonation would be bent differently. So, as far as I can see, no MIDI. Anybody see a way around thsi MIDI limitation? Not a problem for MSP or ChucK.

Since the two are such opposites, it only makes sense that they would make opposite types of music. Still, if the king's pawn game is silent, then something is missing, perhaps "control of center" or "dynamic tension", which would give the king's pawn move a totally different but non-silent sound. This is shaping up interestingly.

Come to think of it, the Pawn-to-King-4 is my preference, musically speaking. You always get notes out of at least the last two pieces moved, so with Pawn-to-King-4 you get a nice gentle opening that builds up steam as soon as supporting pieces come into play. With Pawn-to-Queen 4 you get more sound thrown at you right away. That's one reason I made the musical search depth player-adjustable; otherwise, sometimes things sound too much the same because too many relationships are used for music after each move. Limiting search depth eliminates some of the clutter. I am still getting a feel for what works there. It's exactly like tuning an instrument!

The core of the algorithm is this:

1. Create a directed "reachable graph" that consists of Python 6-tuples, one per board space, consisting of

a. the piece occupying the space after the most recent move
b. the pieces it supports
c. the pieces it attacks
d. the pieces it is supported by
e. the pieces it is attacked by
f. coordinates of spaces to which it can move

Check detection is part of this, as well as special code for castling and en passant pawn capture. I haven't coded for checkmate detection; too many other things to do.

This part is chess-specific, but there is nothing about music generation here.

2. Call a plugin to generate a sequence of tones, where a sequence is a list of Python sublists, and each sublist is a list of tones to be played simultaneously, where each tone is a Python 5-tuple consisting of

a. a bank number to select a voice, used for routing in Max or as a Python index subscript, or could conceivably be mapped to a MIDI channel number
b. frequency (could be mapped to MIDI bend and noteon info)
c. phase
d. left channel amplitude, 0.0 to 1.0
e. right channel amplitude, 0.0 to 1.0

Right now I am using sine waves for support and triangles for conflict relationships, very basic sounds, but the bank number could map to anything.

This plugin also creates a second reach graph, like the first, populating it only with the relationships from the graph of (1) that were actually used.
This plugin also determines the order of search (breadth-first vs. depth-first, for example), depth of search, and generally how to map the structures of (1) to music. So Just Intonation is not hard wired to the overall program, just to the plugin I am using.

The second reach graph gets passed back to the UI for display, hence the black/red/green/yellow arrows on the chess board. Those are the relationships that make music.

3. There are two threads running, one for white and one for black, that are also in the plugin of (2). Their job is just to take the sequences created by (2) (one for white, one for black), embellish them as they see fit (this is where my plugin adds octave info, tempo info derived partly from player move-speed), and send lists of notes off to 4.

4. This step send lists of bank-freq-phase-lamplitude-ramplitude off to a sound generator, for now to Max via OSC/UDP. I will make this Python class a plugin as well, when I get around to ChucK, if ChucK's OSC is on top of TCP instead of UDP. I can't tell from the ChucK docs, although I can find out in 5 minutes by using Ethereal to sniff the ChucK demo packets.

Once I make this a plugin, I could also create a MIDI plugin that converts frequency info to bend-noteon pitch, etc., subject to the many limitations of MIDI in generating sounds outside of equally tempered scales.

A given music plugin can expose as many config parameters to the user interface as it likes, and they show up in a separate GUI window, where you can tweak the instrument to your heart's content as you play, given the limits of the instrument itself. My current plugin exposes most of the Just Intonation roots and transforms, some of the meter data, and the note-search-depth to the player, for inspection and alteration.

I guess now that this thing is getting some character, I am starting to have a goal, which is instrument design in the algorithmic composition space, rather than primarily in the sound generation space, for which there are better experts. I'll put the code up here after I am happy with it, which could be weeks or at most end of summer, because there is some ugly stuff (e.g., unwanted global variables) from the early stages that I want to factor out, and also make the channel to the tone generator more parameterized. Generally, when doing a "reusable" architecture, you don't know if it is really "reusable" until you hit it with two distinct uses, so I probably should do one more music plugin that does equal temper MIDI, just to shake out the architecture.

Then the code will come to this thread. I need to get some conference papers published so I get tenure in my new job, so I'll use any feedback on game-based-instrument-design for that as well as for enhancing the program. But this is not primarily an 'academic study,' it's just play, augmented with a paper or two on the side. I have a potential ally in the music department where I am going to teach CS, so we'll probably foist some of this on students some time as well.

By the way, Kassen, I've been reading The Glass Bead game for the first time in 35 years, thanks to your original post, and have some insights after 35 years or working and playing, that I'll post later. Gotta get back to my day job!_________________When the stream is deep
my wild little dog frolics,
when shallow, she drinks.

Oh, well, now the game has started... next game this may need to be fixed and we might need to consider Nescivi as "queen of the civilised side", right now that's all wrong.

I'll go check her out and probably make the change. Thanks! I was rather hasty in grabbing avatars, my main goal being visual appeal of the icons over strictly light-dark shading, and also using avatars whose owners are posting to this thread (where possible). There were some more I would have liked to use, not enough pieces, although of course you tune this by creating a new 50x50 GIF in the avatars/KB.gif file (for black king, for example), so you can create your own using pets or whatever. American Civil War chess sets (or War Between the States for those of you south of Mason/Dixon) are fairly common over here.

Thanks, I'll take a look. Don't know if the couple of MIDI synths I have support it, but it's worth a look. I also have SC on my todo list, but as with all of us, that todo list never shrinks.

There will be a one hour demo session of this at EM2008 where people can sit down and play some speed chess. With any luck it will be out there virally before that as well._________________When the stream is deep
my wild little dog frolics,
when shallow, she drinks.

If you want I can hack up some nice sounds in SC that you could run with OSC. We could use some custom OSC messages to send midi-like note-on and note-off messages, but with OSC you could use fractional MIDI note numbers or raw frequencies.

I think the white queen's a bit of a mess, well , the picture is, I don't even recognise it. Why isn't Bernat's Avatar the white queen? it's looks perfect for that and she's in the US.

Nescivi turns out not to have a avatar. That's quite annoying. We may have to disqualify her anyway as she's in Canada at last count so that hardly counts as "the civilised world"._________________Kassen

If you want I can hack up some nice sounds in SC that you could run with OSC. We could use some custom OSC messages to send midi-like note-on and note-off messages, but with OSC you could use fractional MIDI note numbers or raw frequencies.

Cool! Write a standard and I'll volunteer for the CK version. If it's going to be OSC I'll wait for a round of OSC cleanup in ChucK though, if you don't mind.... The current situation looks quite messy to me._________________Kassen

If you want I can hack up some nice sounds in SC that you could run with OSC. We could use some custom OSC messages to send midi-like note-on and note-off messages, but with OSC you could use fractional MIDI note numbers or raw frequencies.

Thanks, James. I'll have to hold off on my part until I make the chess-to-sound-program-protocol module a plugin, so this is "planned work" at present, but my current chess-board-to-music plugin uses only two values for voice, one for support relationships and the other for attack. Attack is pretty much tongue-in-cheek, obviously, so I tend to go light on the noise. I'd go for two voices that pair reasonably well.

Kassen wrote:

I think the white queen's a bit of a mess, well , the picture is, I don't even recognise it. Why isn't Bernat's Avatar the white queen? it's looks perfect for that and she's in the US.

Nescivi turns out not to have a avatar. That's quite annoying. We may have to disqualify her anyway as she's in Canada at last count so that hardly counts as "the civilised world".

Point me at an avatar, and on the board she'll go. I agree, by the way, and will move Bernat back across the pond as soon as I have a new Black Queen avatar.

Yeah, Canada's not letting in U.S. citizens convicted of civil disobedience in opposing the war, and presumably they are getting long laundry lists of, ahem, suspected terrorists.

As far as an API standard, I need to get the architecture and example code cleaned up first. For example, I want to put in saved games with automatic replay, including timing, so that somebody else doesn't do this some other way as soon as I post it. I promise to post as soon as I'm happy with it, but I've got to pass some milestones first. It won't be long _________________When the stream is deep
my wild little dog frolics,
when shallow, she drinks.

Wow, this is turning into quite the collaboration! I didn't realize the code was so functional yet. Now I kind of wish there was some kind of contribution that I could make. I know nothing about OSC besides a link to the OSC docs that Jan gave me. Maybe I could help with the games database or something? I presume you'd want to read in text files of games in algebraic notation or something. I know that games databases have been standardized and are available on CD's. Perhaps we could set up the program to interface with such a CD, or perhaps I could create our own little games database with a few sample games in it? Let me know._________________"Let's make noise for peace." - Kijjaz

OK, it looks like I am not going to get away Scot free in spilling out a little premature code. The Python class that sends notes via OSC/UDP is attached. If a ChucK or SC program can accept these packets, it will generate tones. This class WILL change, by the way, when I make it a plugin, but the wire protocol may not. When I make it a plugin, you could create a ChucK or SC specific derived plugin class that manages packets differently. Although, from what I've read of ChucK, it should work with this wire protocol as is unless ChucK OSC uses TCP instead of UDP. I haven't gotten to look at ChucK OSC that deeply yet.

This bit in the code (I hope the spaces are preserved):

Quote:

# The following are for transport which we will hide behind an API later.
from binascii import a2b_hex, b2a_hex
from struct import pack

Creates a header in the UDP data consisting of the word 'list', , four '\0' null characters, a comma ',' character, a type string of "i" for integer and "f" for float, optionally some more nulls to get a multiple of 4 address, and then the actual int and float values as binary fields. This protocol came from having Max send to Python and then I used Python to reverse engineer what Max was sending. From what I've read of ChucK, this should be trivial if ChucK OSC uses UDP. The Max manual claims Max uses OSC.

Here's an Ethereal trace of the UDP datagram's payload in bold for the first note of pawn-to-king-4

Looks like 247.5 hz, when I was expecting a fifth above an A, 220 * 1.5 = 330

>>> 247.5 / 220.0
1.125 Looks like 1/8 above 220.

May be a couple of down tranposes from 440, or may be a bug! Always something to check. The ">" binary format is big endian, which is what Max apparently uses. Anyway,

00 00 00 00 float phase of 0.0

3e c0 00 00 twice, once for left amplitude, once for right.

>>> unpack('>f', a2b_hex('3ec00000'))
(0.375,)
>>>

Anyway, that's the wire protocol at present, so if ChucK or SC can eat these UDP packets, they can work with the existing code. Of course, once I make this a plugin, the code coming into tonegen.send() can adapt the incoming music data to any outgoing wire protocol. I suspect that the plugin that generates music from the chess board (my items (2) and (3) above) and the plugin to send over the wire (4) may have to be unified as one plugin, since music generation may be aimed at a specific sound generator target, anyway. Then the chess engine will work with any sound generation scheme that you care to plug in. We'll see . . .

EDIT: "t = tonegen('192.168.1.3', 7401)" in the attachment should say 'localhost' but I needed to force to another machine in order to use Ethereal.

Wow, this is turning into quite the collaboration! I didn't realize the code was so functional yet. Now I kind of wish there was some kind of contribution that I could make. I know nothing about OSC besides a link to the OSC docs that Jan gave me. Maybe I could help with the games database or something? I presume you'd want to read in text files of games in algebraic notation or something. I know that games databases have been standardized and are available on CD's. Perhaps we could set up the program to interface with such a CD, or perhaps I could create our own little games database with a few sample games in it? Let me know.

The game stuff is all in Python, so a first step will be learning Python, primarily to write your own music plugin after I have things a little more, ahem, solid. Figuring out how to read a game DB into Python might be useful. Or, if you prefer to stay wigth Chuck, custom sound generation. That's one area where I don't get to spend time._________________When the stream is deep
my wild little dog frolics,
when shallow, she drinks.

Or, if you prefer to stay wigth Chuck, custom sound generation. That's one area where I don't get to spend time.

Well, I could code up a class of functions that make some of ChucK's instruments available. That's something that I know how to do. I'm imagining a set of functions that all have the same calling interface, so all the nifty details are hidden from you so that all you would have to do is make a function call like "guitar ();" to get a guitar sound or "pling ();" to get a pling type sound. There should also be an initialization function to set the sound duration and volume.

This would give you a collection of super easy to use sounds to give you a step up from working with sinusoids and triangle waves. Sorry, but I don't know how to make it talk with OSC. Would you like me to put together such a class for the project, AI?_________________"Let's make noise for peace." - Kijjaz

It looks like there is enough interest in playing with this thing, to post the (somewhat volatile) code now. Here it is. Some APIs will change and others may.

Doing the ChucK OSC migration was my plan for last weekend, but I got involved in other aspects of this thing and didn't get to it. If somebody wants to verify whether ChucK OSC works with UDP and this program, May the Force be with You. My plan was just to start out using sines for bank 0 and triangles for bank 1, to have an apples-to-apples starting point; you could change to other instruments for these banks after that. If not, I'll get to it at some point.

I've also included the Max patches in a subdirectory. There's a README.txt.

Have fun.

EDIT: Deleted this attachment when I uploaded a new chess.zip on July 13 on page 6 of this thread.

EDIT: chess.zip attachment remove, see updated code from August 2 for latest version._________________When the stream is deep
my wild little dog frolics,
when shallow, she drinks.Last edited by Acoustic Interloper on Sat Aug 02, 2008 10:25 am; edited 2 times in total

Thanks for posting this. I'm curious to see how the OSC messages appear in SC.

SC listens to UDP datagrams normally -- the question is what the internal parser will do to the data. SC gives it to the user as an array. I'm guessing it will be something like ['list', 0, 247.5, 0, 0.375, 0.375] but I would have to verify before adapting my code above to it.

Thanks for posting this. I'm curious to see how the OSC messages appear in SC.

SC listens to UDP datagrams normally -- the question is what the internal parser will do to the data. SC gives it to the user as an array. I'm guessing it will be something like ['list', 0, 247.5, 0, 0.375, 0.375] but I would have to verify before adapting my code above to it.

James

To figure out Max I just got Max to talk to Max, and then let Python receive the UDP datagrams as well and poked at them inside the interactive Python interpreter. I may have also used Ethereal, although I don't know of a version of Ethereal that catches packets within a single machine. As far as I know, you actually have to go over a wire for Ethereal. (Should be at http://www.ethereal.com but I can't get there right now.)

Good luck! Given my novice status in sound design, I am looking forward to some interesting sounds.

At present the game server sits on one machine and the GUI clients are networked, but my hope in time is to duplicate the server logic as well, so we could play networked games and hear the same music, or perhaps different music for a given game, if we plug in different sound plugins. Right now both players have to be in the same room, unless you stream out the audio.

Take care._________________When the stream is deep
my wild little dog frolics,
when shallow, she drinks.

Right now the message format is really tightly tied to the structure of the Max patch -- I assume the plug-in structure will decouple that and allow other types of messaging.

Yes, even for Max this is limited. Since the "music plugin" generates the sequences and the "wire plugin" sends them down the line, the part that actually determines what fields to send can probably be part of the "music plugin" (it isn't right now), and the "wire plugin" can be neutral about the format, for example just send a UDP datagram without worrying about its contents. Basically, we can push the application-level-protocol back into the "music plugin," and, where possible, have the latter generate application formats that will work for Max, SC or ChucK. I guess I am going to learn some OSC the old fashioned way

Quote:

Anyway, no doubt in my mind now that you will be able to control supercollider this way.

Jebus, you guys are talking way over my head! I know nothing about interprocess communication except I can't do it, and Python is a mystery to me as well. Cool concept though. Wish I could help, but it's outta my ballpark! Happy coding._________________"Let's make noise for peace." - Kijjaz

Oh, well, now the game has started... next game this may need to be fixed and we might need to consider Nescivi as "queen of the civilised side", right now that's all wrong.

All wrong and getting worse

Quite a bad position to be in, over-aggressive and exposed to the world, so it seems.

Hermann Hesse wrote:

Here and there in the ancient literatures we encounter legends of wise and mysterious games that were conceived and played by scholars, monks, or the courtiers of cultured princes. These might take the form of chess games in which the pieces and squares had secret meanings in addition to their usual functions. And of course everyone had heard those fables and legends from the formative years of all civilizations which ascribe to music powers far greater than those of any mere art: the capacity to control men and nations. These accounts make of music a kind of secret regent, or a lawbook for men and their governments.

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum

Please support our site. If you click through and buy from our affiliate partners, we earn a small commission.