Page  00000001 An Interactive Cellular Automata Music Application in Cocoa Dale Millen Emeritus faculty, University of Arkansas dmilen(~comp uak+edu Abstract Certain cellular automata have visual characteristics that make interactive computer music performance possible. An application has been written using the Cocoa objectoriented language with Objective-C that allows the performer or composer to control which columns of cells are enabled for mapping to pitches and durations as the program is running. Other parameters that can be changed interactively include tempo, enable/disable for sixteen MIDI channels, and pitch transposition to any degree for each MIDI channel. Changes made to control parameters during runs can be saved to file and used to play back a performance. An editing mode permits detailed control of all interactive parameters which saved to file can be used in the play mode to achieve a controlled rather than improvised performance of a composition. 1 Introduction Design goals for this version of Cellular Automata Music included implementation of the following features: - an improvisational interactive run mode where the user can change control parameters based on visual observation of the evolving cellular automaton displayed on the computer screen as the application is running. - methods to record and save to file all control parameter changes made by the user during a run. - a play mode to open and to play recorded and/or edited performances from saved files. - an edit mode to permit accurate control over all aspects of a performance, control that is not possible to achieve in the run mode with improvised parameter changes. 2 The Application The Cellular Automata Music application provides an interactive computer music experience for the user who is guided by the visual information and appearance of a cellular automaton display on the computer screen in making compositional and performance choices. Certain cellular automata have vertical cellular formations containing patterns that repeat with specific periods. These formations are several cell columns in width. Each individual column may have a different short repeating pattern of state values that can be used by the composer to create a musical passage by combining the pattern in parallel with other patterns in the formation or by employing the pattern sequentially with other patterns in the formation. The user can click on these cellular formations with the mouse to enable the cell column of interest to be mapped to pitch and duration as the application is running. Controls are provided to move the enabled column number one cell to the left, minus one, or to the right, plus one, to adjust which column within a pattern is enabled for a particular channel, an adjustment which would be impossible or difficult to accomplish with the mouse if cell sizes are small. The appearance of cellular automaton patterns on the screen other than the repeating vertical patterns mentioned above could suggest random or variable cell state patterns that would contrast effectively with repeating patterns. A composer might choose to create a background consisting of a combination of repeating patterns and might select a random or variable pattern to play against this background. The choice of method to map cell states to pitch and duration is an arbitrary one. There are many mapping possibilities including diatonic, chromatic, or pentatonic scales as well as composer created mappings. The present implementation of Cellular Automata Music maps cell states to pitches using the diatonic scale and provides the possibility of the transposition of these pitches to any scale degree. This mapping seems to work in instances where many channels are simultaneously enabled for greater densities of sounding voices. The size of the cellular automaton display view is 713 pixels in width and 525 pixels in height and a cell size of one is equal to one pixel. The image is drawn into a scrollable view that is 10000 pixels in height. When the cellular automaton run reaches the bottom of the display view, the program automatically scrolls the scroll view one row up after each time step for the remainder of the run until the maximum allowed length in the scroll view is reached. A time step consists of the calculation and display of one complete row of cells. Each time step is triggered by a Proceedings ICMC 2004

Page  00000002 timer pulse that causes the row to be calculated and then displayed on the screen simultaneously with the sounding of pitches mapped from the enabled columns. The value of a time delay variable determines the rate at which the repeating timer fires and serves as an approximate control of tempo. All pitches begin with the pulse trigger but have various durations that are mapped from the sums of cells in neighborhoods. Some pitch durations may overlap newly sounding pitches of the next time step. Since CPU time can vary in calculating and displaying a row of cellular automaton information, tempo control is only approximate and is just a selection of relatively faster or slower tempo options with each choice of cell size. 2.1 Run Mode Before entering the run mode, the user must choose the type of cellular automaton to be run, K3R1, K2R1, or K2R2, and must enter a code rule number representing a rule for this type in the appropriate text field. The ENTER button for that field calls the method that converts the base ten code rule number to either a base three number or a base two number for use in the mapping calculations. The user then selects a cell size 1, 2, 5, 10, or 20 and enters initial cell state values. If the cell size is 5, 10, or 20 the initial cell states can be entered with the mouse in the grid at the top of the view. For cell sizes of 1 or 2, the user must press buttons to enter the center cell state value or randomly generated state values across the entire grid row. 2.2 Edit Mode In the edit mode, the user can step through a cellular automaton one time step at a time by pressing the button marked with a "+" located adjacent to the EDIT button. The "+" button causes the next time step to be executed and drawn to the view screen. All control parameters can then be adjusted as desired for the current time step number. These control parameters include MIDI channel enable/disable, pitch transposition for each channel, column number assignment for each channel, and tempo. At the end of the editing process, the user can save the edited performance as a play file by choosing "Save" from the menu bar. The current time step number is displayed in the "step" text field near the EDIT button and the number of time steps that had changes made to one or more control parameters is displayed in the "array index" text field. 2.3 Play Mode Control parameters are stored in arrays indexed by the number of steps that had control changes during a run. The step numbers where changes were made are saved in an array that is used to control the execution of parameter changes in the play mode. Play files can be opened from the menu bar and played in the play mode. The successful opening of a play file enables the PLAY button. All recorded parameter changes are made at the proper time step in the play mode as the cellular automaton is realized on the screen. Control parameters are also recorded during improvised performances and can be saved to play files. 2.4 Stop Button The stop button ends a run, edit, or play mode function and enables controls that were disabled during those modes. After pressing the RESET button, the user can enter a new rule code and run a new instance of the currently selected type, or the user can make new choices in all parameters before the next run. After the STOP button has been pressed, the user can choose the "Save" item in the menu bar to save the control changes made during the run as a play file. 3 Cellular Automata types Cellular Automata Music was written to implement primarily a specific cellular automaton, a totalistic type (Wolfram 2002) K3R1 that has a neighborhood of three cells and a range of one cell on either side of the center target cell. Each cell can have zero, one, or two as its cell state value. Cell state value zero is represented by black, cell state one by red, and cell state two by yellow for drawing the K3R1 cellular automaton to the computer screen. A totalistic cellular automaton rule is based on the average of the sum of the cell states of the neighborhood. For K3R1, there are seven possibilities, zero through six, for mapping to the cell state of the target cell on the next time step. The totalistic K3R1 cellular automaton type has 2187 rules (0 - 2186) that are assigned base ten code numbers that the user enters in the appropriate application text fields. The application converts these base ten code numbers to the base three rule used by the application to compute the K3R1 cellular automaton. Rule code number 1599 is ideally suited for this interactive cellular automata application and has been used by the author to create a composition entitled Hanging Gardens. To accommodate the complete horizontal and vertical visual extent of this automaton with a cell size of one pixel, the view must be approximately 700 cells in width and 10000 cells in length. The 1599 K3R1 automaton, from a single center cell initial value equal to one, reaches a steady state condition after 8282 time steps. 4 Mapping While a totalistic type rule is used in the application to determine cell states in the future time step, the mapping of pitch to only six possibilities is perhaps not very interesting musically. Pitch mapping for the K3R1 automaton is instead handled by a separate mapping procedure using the position of the cell state numbers, 0, 1, and 2, within the Proceedings ICMC 2004

Page  00000003 three cell neighborhood. Each permutation is mapped to some arbitrary pitch based on a count of the number of times the permutation occurred during an actual run of the cellular automaton. Cellular automata with totalistic rules are left right symmetrical when realized from an initial state of one center cell. Mirror image cells, however, in Cellular Automata Music can produce different pitches if pitch mapping is by cell state position rather than by cell state sums over the neighborhood. The sum of cell states (0 - 6) in the neighborhood is used to determine durations. The sum is multiplied by a scaling factor chosen to achieve durations in the desired range. Also implemented are cellular automaton types K2R1 and K2R2. K2R1 is a simple type of cellular automaton and has 256 different rules. See Wolfram (2002) for a complete K2R1 catalog. K2R2 has a neighborhood of five cells with each cell having a state value of zero or one. State position mapping is used to map to future time steps for K2R2 rather than totalistic rule mapping. State position mapping greatly increases the number of possible rules for this cellular automaton. 5 Interface Builder The user interface for the application is designed and constructed with Apple Computer's Interface Builder. All interactive controls are placed near the cellular automaton display view and are always available to the user without reference to the menu bar. However, less frequently used functions such as save to file and open from file are located in the menu bar. Controls are enabled or disabled by the application code depending on whether the current operational mode is run, play, or edit. Selection of a channel to be enabled for the setting of a column number or for transposition can be accomplished by depressing keys "q" through "i" for channels 1-8 and keys "a" through "k" for channels 9-16. The key options make it possible to select the channel while clicking the mouse on the screen to select the column that will generate pitch and duration for that channel. Buttons are provided to enter initial cell states for a run. With larger cell sizes such as five, ten, and twenty, the user is able to enter initial states by clicking on or dragging over cells with the mouse. The yellow color with cell state value of two in the K3R1 cellular automaton is entered with control key plus mouse click. With cell sizes of one and two, the cells are too small for the user to enter states with the mouse, so buttons are provided to enter single center cell values of one or two. Buttons are also provided to enter randomly generated initial cell state values. 6 Music The application user selects voices on a MIDI controlled device, connected to a Macintosh computer running OS X 10.2 or higher, that will play sounds or voices on MIDI channels one through sixteen. Because of the pulse-based nature of the program and tempos that are often fast, sounds or voices with short amplitude envelopes and of a percussive quality are perhaps most effective. With slower tempos, voices having envelopes of longer durations may be effective. Sixteen channels are provided so that a variety of voices will be available to achieve different groupings of two to perhaps five "instruments". The user is able to change the composition of these groups during the performance. For greater density of sound, up to sixteen simultaneous voices are available. The interactive design of the application makes it possible for the user to make these judgments based on the visual appearance of the cellular automaton on the screen. Complex patterns may best be used alone or in limited combination whereas short repeating patterns may be effectively combined in larger groups. An important consideration in a music composition related application is silence. Cell state zero is mapped to durations of zero in the application. This causes large areas of state zero to be skipped in cell rows but does not in itself produce durations containing silence. The user can achieve periods of silence by enabling cell columns that go into zero state areas represented visually by black color and obviously by disabling channels so that no sounds are produced for certain time steps. 7 MIDI Implementation Apple Computer's CoreMIDI.framework and CoreAudio.framework are used to implement MIDI in Cellular Automata Music in addition to the Cocoa and AppKit frameworks. Note on and note off data for a channel is added to a MIDIPacketList. At the end of the calculation of the row of cells in a time step, a MIDISend is executed simultaneously for each enabled MIDI channel. Durations are handled with timestamps that have a beginning time of zero (now) so that all notes for a time step begin with the timer firing. The duration variable value is calculated from the sum of the neighborhood cell states multiplied by a scaling factor. This number is converted to nanoseconds, duration multiplied by 1000000000, and then converted by AudioConvertNanosToHostTime(duration) to the host time used to calculate the value of the timestamp for the note off. 8 Future Features - QuickTime voices option. - more accurate control of tempo. - pitch mapping options - two and three dimensional cellular automata Proceedings ICMC 2004

Page  00000004 Screen capture of Cellular Automata Music running the cellular automaton K3R1 rule 1599. References Beam, M. and Davidson, J. D. (2003). Cocoa in a Nutshell. Sebastopol, CA: O'Reilly & Associates, Inc. Davidson, J. D. and Apple Computer. (2002). Learning Cocoa with Objective-C, Second Edition. Sebastopol, CA: O'Reilly & Associates, Inc. Hillegass, A. (2002). Cocoa Programming for Mac OS X. Boston, MA: Pearson Education, Inc. Wolfram, S. (2002). A New Kind of Science. Champaign, IL: Wolfram Media, Inc. Proceedings ICMC 2004