Post Ca2

After CA2, I proceeded to work on confucius computing. The idea is to have a situational cultural learning experience to have a virtual confucius embedded into the system. I have done a lot of research and reading up his teachings and tried to categorise them. We had to also come up with various applications and algorithms in order to track some of his teachings that are subtle like how to be virtuous. More updates in this area is in the main age invaders webpage.


I've been given a new task to work on so that my fyp has more direction. I am suppose to create a graphics/music toolkit for the age invaders system so that future programmers can program any applications on the platform easily. After working on confucius computing for about 2 months, I'm a little disappointed to not see it through. I think the project has a lot of potential but i probably won't have enough time left for my fyp. It's probably better for my fyp to do the toolkit since it seems to give it more direction and a more linear path of progression so that it'll be better graded.

About less than 4 months to go, I've gotta start exploring this new task and get it done! On the other hand, I've started on my thesis, only the introduction, but it's a start at least.


I decided to look into the shortcomings of the present system before deciding what to work on:

  • C++ software library
    • Must know C++
    • Complex
    • Manually refresh
  • Burning of EEPROM
    • Individually burn them using the GALEP burner.

I have to decide on the goals of the toolkit. The goals and objectives the toolkit has to meet are as follows:

  • Simple for general developers like musicians or teachers
    • Display LED images
    • RFID tracking of devices. (slippers)
    • Input/Output of other Bluetooth devices.
  • Extend to multiple uses
  • Modular and easily extendable
  • Burn images to EEPROM via Ethernet

I have decided to program the toolkit on MAX/MSP above the C++ library layer. This is because the Max environment brings about the following advantages:

  • visual patching software environment
  • Open-source objects
  • Constantly running programming environment
  • Easy for MIDI/Video processing

It was not as easy as I thought it would be, coding objects into the Max/MSP platform. Despite reading the thick manual on the cycling74.com website on how to write externals, I was only able to write simple externals in C. The main problem is that the previous library is coded in C++. One way is to recode everything back in C but that is a silly solution since so much work was done in the C++ library and it required me absolutely no knowledge of the underlying firmware details. I have managed to find flext which is a cross platform programming platform for pure data and Max externals. It uses C++! Another thick wad of manual to look through…


The flext is really complex. I guess it's focus is how to design modules that are cross platform for both pure data and Max. I can't even get a simple example going. Too much to understand. I have posted on the forum to ask for help. Just need a simple lightweight example of C++ coding of externals. Keeping my fingers crossed.


I'm amazed at the the Max community. They replied me within a day. (couple of hours actually). Apparently, there was a C++ template for simple externals by Graham Wakefield. I shall look into that.


Phew. The template was really useful. I managed to code some simple externals previously in C. I think this is the solution… I can transfer the entire C++ library onto here. The template is lightweight and easy to understand. Basically, he overloaded new and deletes operators to allow Max to manage memory while still calling his own constructors. The result is that an instance of the external is encapsulated by an instance of the C++ class. Thus, it allows the programmer to program just like in C++ and uses any stl-classes available. It uses extern to tell the C++ compiler that they program uses C linkage in order to use the C library for programming externals. Thus, this allowed me to code the externals in C++ and use the previous C++ library functions for the age invaders platform.

Basically, the task of writing an external object for Max is to write a dynamic link library that is loaded by the Max environment. This library calls upon routines in the Max environment. Therefore, the idea is to create a class of the object. Instances of this class will be called when messages are sent to the object. The template provided is just like a C++ object class. It has a data structure with the variables and methods you create in the header file. (stl data structures can be used too.) The constructor and destructor determine how instances are created and destroyed.

The constructor should initialize member variables and determine what is on the object when it is created. It should specify how many inlets and outlets to create. Then in the main, you will have to add attributes and allocate a memory to it. This is done automatically by one of the external libraries using the attr_offset method. Next, the developer will then bind the class methods using class_addmethod to the various inlets. The Max environment also automatically detects simple data structure such as a float, integer or message and you can determine the method to use in each of the cases with the same inlet. There are also reserved key words such as anything type of input which calls the relevant method when it doesn’t fall into one of the standard cases. Lastly, you will have to code what the methods do accordingly. The challenge in writing an external is to make the object generic and modular so that it can be used repeatedly in many cases and can interact with other objects.

Graham Wakefield’s C++ wrapper template was used for programming of externals as it is lightweight and easy to understand. [9] Basically, he overloaded new and deletes operators to allow Max to manage memory while still calling his own constructors. The result is that an instance of the external is encapsulated by an instance of the C++ class. Thus, it allows the programmer to program just like in C++ and uses any stl-classes available. It uses extern to tell the C++ compiler that they program uses C linkage in order to use the C library for programming externals. Thus, this allowed me to code the externals in C++ and use the previous C++ library functions for the age invaders platform.


I have been really busy coding objects onto the Max platform. Will update on all the objects soon. Currently, the two objects of piority is to display an image and to read input from the bluetooth devices. Meanwhile, there is the thesis to worry about.

Objects have to be:

  • Modular
  • Simple – Click object + name
  • New functions
  • Easy to access help file

Haven't updated in a while. These are the objects that i've finished. I'll add a section with detailed explanation of all the objects when i'm more free.

  • Aiinit
    • Initialises the board
  • Aipic
    • Manipulates images
  • Shoe
    • Controls Bluetooth device

More objects:

  • Convert
    • Convert board number to coordinates

I've also figured out the bytes to burn to the EEPROM.


More objects:

  • Instrument
    • Loads instrument and plays note
  • Move
    • Movement of images according to Bresenham’s algorithm
    • Speed control

I find it troublesome to code some kinds of logic in max. Managed to find these objects by other people to help. This helps in coding for people who are more familiar with javascript or C language.

Other external objects for scripting:

  • Rtcmix~ and Js
    • Scripting objects

The burning of EEPROM works in C++. Now i have to write an external for max.
The bytes to write are:

Byte 1 - 0xC0 (header byte)
Byte 2 - 35 (length - number of bytes in the data portion of the packet 5-37)
Byte 3 - 0x80 (command byte)
Byte 4 - 0 (layer byte - not applicable)
Byte 5 - The position in the EEPROM that you wish to burn the image to. 0-255
Byte 6-37 - The data for the image


  • Wrote a burn object for burning of EEPROM
    • Process data into the buffer
    • Take in commands for burning

Made a user interface for the burning of EEPROM on Max.
These are the features:

  • Draw any image
    • Can draw on the 16*16 drawing board any image you wish
  • Burn single board
  • Backup data
    • can save data in a file and reload it

  • Transfered pervious walking musician demo that was on C++ and Max all into Max.
    • This shows that the Max toolkit can achieve what was previously done.

  • Wrote a pong demo to show the capabailities of the toolkit
    • Able to program logic
    • Display pictures efficiently
    • Add in music
    • Change parameters in real time
    • Interface with other interesting objects such as an Apple laptop with built in gyro-sensor

  • Thesis and tech paper first draft done
  • CA3 presentation over.
    • To note: Compare previous code vs Max

I think CA4 went pretty well. Rushing deadlines for other modules. Will update the details for all the objects soon.

  • Revised Thesis/ Tech paper
  • Update PPT for CA4
  • CA4 - presentation + demo
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License