-
Notifications
You must be signed in to change notification settings - Fork 15
Software Basics
The software team of RobOrchestra deals with writing code that controls the performance of the orchestra using timed MIDI messages. We write music generation algorithms that generate unique polyphonic music in real time. Because many of our algorithms are probability based, you will never hear the same piece twice when running our algorithms! We currently have two different methods we use to send MIDI messages to the orchestra: Processing's MidiBus Library(recommended for windows users) and the Java Sound API(recommended for mac users). Regardless of your computers operating system, it is recommended you set up both methods.
The RobOrchestra software team primarily codes in Java. If you are new to Java and object oriented programming, there are many resources online! Some recommended resources:
- Java Code Academy Course: for those new to programming entirely
- Object Oriented Programming Terms: for those new to object oriented programming
- The Java Tutorials : comprehensive Java tutorial for those with experience in another language
- Download Processing and install it. Processing is a java-based software sketchbook that has many convenient libraries for creating audio and visual art.
- Open Processing. In the toolbar navigate to sketch>import library>add library. In the search bar type in "midi" and the library called "The MidiBus" should come up. Select the library and click install.
- To test your setup, navigate to Examples/MidiBus_TestCode on the Github repo and open the file MidiBus_TestCode.pde. The file should open in Processing. Press the play button to run the code. If you are not hearing sound, you may have to alter the global "output" variable. Once you run the code, a list of available MIDI Output devices will appear in the console along with their indexes. Alter output to these options until you hear sound when the code runs.
- Mac users may find they do not hear any sound from their speakers no matter which output they choose. This is a known problem with the MidiBus library, therefore it is recommended that Mac users use the Java Sound API when writing their code. Mac should still be able to send MIDI output to the orchestra without any problems using the MidiBus, however.
- Download the Java Developers Kit and install it. The JDK includes the Sound API that we will use.
- Install a Java IDE of your choice. Some commonly used ones are NetBeans, Eclipse and IntelliJ. The IDE is just an environment where you run and edit your Java code, so you can use any program you like.
- Download Processing and install it.
- To test you setup, navigate to Examples/Midi_Interface_Test in the Github repo, and open Midi_Interface_Test.pde. The file should open up in Processing.
- Run the code by pressing the play button. If you are not hearing sound, you may have to alter the deviceIndex variable. Once you run the code, a list of available MIDI Output devices will appear in the console along with their indexes. Alter deviceIndex to test each of these options until you hear sound when the code runs.
This method has known issues for Mac users. Untested on Linux.
###Processing The MidiBus is a library for Processing that allows us to send MIDI signals to either our computer speakers or to the RobOrchestra via USB. Processing is really a simple IDE for Java, so any java functions or syntax can be used in processing. What separates Processing from Java is that .pde(processing files) all have a setup() and a draw() function. The setup() function is run once when the code starts and then the draw function runs and loops until the program is stopped. Also unlike with Java, not everything in Processing has to be a class. You can define functions and variables directly, like you would in Python.
###Example For a simple example of how RobOrchestra uses the MidiBus library, look over the file Examples/MidiBus_TestCode/MidiBus_TestCode.pde on the Github repo. This program sends the MIDI notes of a chromatic scale to either your computer's speakers, or Xylobot if it is plugged into your computer.
The function MidiBus.list() prints to the console a list of your computers available MIDI ports. When RobOrchestra is plugged in, it will come up in this list as "USB-MIDI-2.0"(or something similar). Use the output of this function to alter the input and output variables of the MidiBus to route signals to your speakers or to the orchestra
The MidiBus Library Documentation contains information on all MidiBus classes and functions. Of importance to RobOrchestra are the MidiBus class, the Note class, the MidiBus.list() function and the MidiBus.sendNoteOn() function
If you're interested in learning more about processing, you can check out the Reference and Example pages on the Processing website
This method works for both Windows and Mac. Untested on Linux.
Because writing code using the Java Sound API can get a bit "wordy," RobOrchestra has a library of wrapper classes that can be referenced to substantially simplify your code. These wrapper classes are designed to mimic the flow of working with the MidiBus Library. To use these wrapper classes, copy the files located in the "Java MIDI Wrapper" folder on the github repo into the same directory as your code. This will allow you to reference the classes from your code.
For a simple example of how RobOrchestra uses the Java Sound API and wrapper classes, look over the file Examples/Midi_Interface_Test/MidiBus_Interface_Test.pde on the Github repo. This program sends the MIDI notes of a chromatic scale to either your computer's speakers, or Xylobot if it is plugged into your computer. It references the three wrapper classes: DeviceList, Orchestra and NoteMessage. This test code is written in Processing(hence the .pde extension), but can easily be modified to a .java file by encompassing the example code into its own class.
For information on the RobOrchestra Wrapper classes and their functions, look over the commented source code in the "Java MIDI Wrapper" folder on the Github.
If you are interested in how the wrapper classes are implemented, you can check out the Java Sound Programmer Guide which has documentation for all classes and methods of the Java Sound API.