MSQ.BAS DMS Science Fair, May 1992. June 1997 by Marc Kummel aka Treebeard. Contact mkummel@rain.org, http://www.rain.org/~mkummel/ About MSQ ----------- MSQ (Midi SeQuencer?) is BASIC code from the vault (1992) that combines my interests in math and music to do Algorithmic Composition with MIDI. MSQ can take various mathematical functions (formulas, fractals, various random distributions, etc) and map them to MIDI notes and play them on attached synthesizers. It has enough editing and recording functions to qualify as a full-on sequencer. DOS Cakewalk was the inspiration for some of the menus, but I made it my own. You can create a track using an algo-comp math function from the Compose menu; transpose and time-shift it from the Edit menu; add a live track with your keyboard from the Tape menu; and then save it all as a sequence from the File menu. Not bad for a BASIC program! MSQ has lots of other goodies such as a MIDI Trace screen that can report MPU events as well as MIDI events, and a full-featured calculator. Looking back at this project, I'm amazed what a big ambitious program it became. Maybe too big! I originally wrote MSQ with Quick Basic 4.5, though I think I upgraded to PDS 7.10 while I was working on it. Even with PDS, MSQ grew to the point that it will not run within the Basic editor/IDE. What a pain! I tried to get around this by creating various LITE stub files for different modules and routines that would allow me to run just the routines I was working on. Unfortunately I also eliminated most comments, so I can only guess now what some of this code does. It uses some strange conventions, such as using constants c1 c2 c3... instead of the integers 1 2 3. Anything to save a byte, but I don't think this helped much. I think MSQ was the first really big program with windows and menus that I wrote for color VGA rather than monochrome Hercules video. The screens look good, but they are clunky because they use the hard drive as a buffer for screen windows, since VGA screens are too big to store in conventional memory. That's why your disk will spin so much as the program runs. I vaguely recall using a ramdrive for buffer space as I wrote his. Now I would use EMS or XMS. Buffer and other scrap files in your MSQ directory all have the extension .TBB (TreeBeard Buffer?). MSQ should delete these files when it quits, but you can safely do so if it misses any. Just type "del *.tbb". MSQ does not need EMS expanded memory, though it's linked with code overlays, and I think the overlay manager can use EMS (not XMS?). Without it, there will be even more disk thrashing and delays while it loads different parts of the program. MSQ can speak MIDI only with a Roland-compatible MPU MIDI card. I use a MusicQuest card. Sound Blaster MIDI will NOT work since MSQ uses the "smart" features available with the MPU, and at least old SB cards can only do MIDI in "dumb" UART mode. Without MIDI, you can still create MIDI tracks and view them from the Edit menu, but you won't be able to play them. The Roland MPU is a separate computer-on-a-card with a protocol that dates back to the days of computers like the Apple II and the original IBM PC. In "dumb" UART mode, the MPU just passes bytes to the MIDI chain, and it's up to your computer to handle all the details of timing, etc. In "smart" mode, the MPU still passes MIDI commands on to your synths, but the MPU also responds to commands that program the MPU processor itself to do different things with/to the data it receives in realtime. With the right commands, the MPU in "smart mode" can handle all the timing details of multi-track MIDI playback and do automatic filtering and translating. It's MSQs job to follow the MPUs handshaking conventions and feed it the data it needs, when it needs it. This system works well enough to support a multi-track sequencer written in Basic! But it's probably obsolete (for most of us) now that the gory details are hidden inside Windows device drivers. My program depends on the MPU to do much of the work of playing back a sequence. It won't work without it. MSQ also needs to find your MIDI card. The default MPU address is (hex) 330. If yours is different, say (hex) 300 like mine, then start MSQ with /A300 or add SET TBMIDI=300 to your AUTOEXEC.BAT file. MSQ does not use MIDI interrupts. MSQ can load and save MIDI tracks in it's own format as .MSQ files, but it can't save or load Standard MIDI Files (SMF) with a .MID extension. I recently added a small utility MSQ2MID that will convert a MSQ file to a generic SMF type 1 MID file. To convert a file named test.msq, just type "msq2mid test" at the command prompt, and the program will make a file named test.mid in the same directory. MSQ2MID uses running status by default, but you can disable this if you add a "/N" option to the command line. MSQ2MID only converts MSQ tracks that are ennabled for PLAY. My MIDTXT program (also available from the Vault) is a useful tool for examining and playing MID files in DOS. After converting, you can load the new MID file into Cakewalk or any other Windows Sequencer. Some of the the algo-comp routines available from the MSQ Compose menu (especially Logistic_Iterations and Cantor_Canons) are musically interesting and one of a kind. They may not be great music by themselves, but they could become an interesting part of other compositions... MSQ has a few functions in its menus that use a 12-bit IBM DACA analog-to- digital hardware card that I bought as surplus many years ago. Tape\Analog is pretty cool. It senses a 0-5 volt analog input and maps it to MIDI output, you can play MIDI with a joystick or a temperature probe! You probably need the exact same hardware card to use this function. I can't run MSQ under Windows. I get a message that the MIDI device is already in use. Is there a trick here? Running MSQ ------------- To run MSQ, unzip the archive into a directory and type: MSQ [/A] If you get a message saying "MPU not responding!" then MSQ cannot find your MIDI card, or it is not MPU compatible. Check your hardware and try again. You may need to let MSQ know your MPU address with the /A option. To exit the program, type ileuit, ie alt-f-q. MSQ does not use a mouse, but it uses menus and windows in an intuitive mouse-like way. The menus actually work pretty well with the keyboard once you get used to them. Press and then , or the first etter of a menu, and use the arrow keys to navigate. always cancels. Some screens such as Edit\Notes show a cursor which you can move with arrow keys using and to select and cancel. Once it starts, MSQ is easy to navigate, but it has *lots* of menus. Some options (including Help) don't do anything yet, but most options work. Start by composing and playing a track of random notes. Press and then for Compose. Press to pick the first option of Stochastic Noise, and a menu will open. The default setting for White Noise is pretty boring, just random notes, so press a few times on the Algorithm line until it brings up "1/f noise". The defaults should work fine, so press the down arrow to bring the select bar to Play and press to begin. You should hear random (but not TOO random) MIDI output on channel 1. Press to stop playing. Now bring the select bar down to the bottom of the menu box and select "Compose Track". It will work for awhile, and then you will see a new item in the Track box on the left side of the screen, "2500 events in track 1". You can play the track by selecting Play from the Track menu, or press to close the menu bar and just press

for play. You will hear the track and see a nice piano-roll display of the MIDI notes as they play. You can select patches and add comments from the dit menu, and you can select ave from the ile menu to save your tracks as a MSQ file. You can later use the MSQ2MID utility to convert this to a MID file that you can load into your favorite sequencer and use in your own compositions. If it all works, you're ready to explore! MSQ Menus ----------- Some of the menu items are just part of my wish list ("nada"). Here are the choices that actually DO something. MSQ has more features than I can remember, so you'll have to try each option to see what it actually does. Most of these menu items have their own sub-menus or windows. This is the only help. SYS System menu: general settings and info, and a few goodies. --- Info About MSQ. Desktop Nada Colors Change screen colors, nice editor. I used to load PRINTER.PAL to get nice screen dumps on my Citizen MSQ-10 dot matrix printer. Files Where MSQ is finding and putting its files. Printer Select between 3 Epson FX clones. Sorry, that's the only printer it supports. You can always load GRAPHICS.COM and press for screen dumps. Devices Nada. Memory Memory statistics. Locate Move a cursor around and get (x,y) coordinates. I used this while developing MSQ. Randomize Reset the random number generator from the system timer. Edit Screen Nada. Calculator An early version of the code that became EVAL (available from TBVault). A full featured calculator that can parse expresions. The calc routines are also used by the Compose\Graph option to map equations as sounds. Type "?" for help and "quit" to get out. Time A nice clock that shows system time. DOS Shell Spawn a DOS shell. MSQ doesn't release any memory so this is only good for small utilities. Type "exit" to return to MSQ. FILE File menu: save, load, print, and exit ---- New Clear all track data. Save Save the current track data as a MSQ file. Save As Load Load a MSQ file from disk. Current track data is lost. Merge Load selected tracks from a MSQ data file. After you pick a file, you will have the chance to edit a load list for the file saying which tracks to load (or not load) and where to put them. Print Print screen or data. Epson FX is the only printer supported. (This is *old*!) Quit Quit the program. TAPE MIDI play and record menu. ---- Play Play the selected tracks. If the menu bar is not selected, you can also press

to play. Press to stop. Record Record a new track from MIDI-IN. If no track is selected for REC mode, you will be prompted to select one. Start playing after the lead-in, and press when done. Play Step Nada. Record Step Insert Record a track and merge it into an existing track. If other tracks are selected for PLAY, you will hear them as you jam. If no track is selected for REC mode, you will be prompted to select one. Start playing after the lead-in, and press when done. Analog Record a MIDI track that tracks input from an IBM DACA analog to digital card. Sorry, you can't use this function if you don't have the hardware. Mode Change the mode of each track between Off/Play/Record. Use the up/down keys to select a track, and press to toggle the mode. You can play up to 8 tracks at once, but you can only record one track at a time. Tempo Change playback and metronome speed. Settings Various MIDI and MPU settings. The default has MIDI-ECHO Filters ON since I use an old Casio CZ-101 keyboard and echo all Controls key events to an external Sound Canvas that comes after my computer in the MIDI chain. Change this if you hear every note twice! (Sorry, there's no way to change the default without editing the source code.) Trace MIDI Trace screen that can trace MPU events as well as MIDI events. Press for record mode and watch all the action. You can directly program the MPU as well as your synths from this screen if you know the right byte codes. (Press for some help.) You can also really screw things up! You will have an option to do a MPU reset when you quit. Keys Off Send a note-off to every note on every channel. This is the Panic Button if notes get stuck. Reset Send RESET code to the MPU. Recommended if you alter settings using Trace. EDIT Edit Menu to edit/view existing track data. ---- Track Edit track settings, loop tracks, add comments, etc. Measure Select measures for later editing commands. Notes Open a piano-roll display of the action on selected MSQ tracks. There's a cool editor for selecting notes and changing them. Press arrow keys to move between succesive events and press to edit. You can change the note and the time. Events Open an Event-list window of the action on selected tracks. You can edit the events IF you know what you're doing. Actions These don't work. Conductor Drumkit Fades SysEx OPTIONS Edit tracks. You pick an option and THEN select what track to ------- do it TO. Copy Copy all or part of a track to the buffer. Paste Paste the buffer to a track. Delete Clear all or part of a track. Move Move one whole track to another. Loop Repeat track data a number of times. Kill Delete whole tracks. Remap Nada. Extract Transpose Transpose a track. Slide Time-shift a track ahead or behind. Envelope Nada. (What was I thinking?) Match Quantize Humanize Invert Fit Time Key Time Filter Create an event filter to use with other Edit options. Empty Scrap Delete the scrap buffer. Undo Undo the last Edit action. MARK Mark a place to edit or goto later. You can press the function ---- keys during playback to set a mark. From Thru All GOTO Goto a previous mark. ---- From Thru Count Nada. Search COMPOSE The most interesting part of MSQ for me. Use different math ------- functions to compose MIDI music tracks. Also some nice graphic fractal routines. You have to know something about fractal math to understand some of the settings. Many books and articals are available. The Mandelbrot and Julia Set options use complex arithmetic with i=sqr(-1). CMATH is a good calculator for complex math that is available (with source, of course) from Treebeard's Basic Vault. Each different compose method has its own further options and menus for sound and sometimes graphics. The MIDI Settings menu within each option lets you set details like tempo and which tracks to record. For most options, select Play to hear a sample and Compose to actually record a track (using current Settings). Musical results vary. My favorites are Logistic Iterations, Scales, and Cantor Canons, but even White Noise can make a useful track in a sequence. Stochastic Noise Various kinds of random notes with 5 different algorithms and 10 different random number distrubutions to use with each. The default White Noise is the least interesting of the lot. Try the Distribution option to see a graph each distribution. Mandelbrot Set Play Mandelbrot Set fractals with lots of options. You can either step through a picture point by point, or iterate a single point. The latter is more interesting musically. Select a point with the Sample/Select option, and select Play to begin (and plot) the iteration. Points in the blue center of the Mandelbrot Set will iterate for a long time, but other points will run away sooner or later. Check the Play, Plot, and MIDI Settings menus for MANY options to play with. You can also zoom into the Mandelbrot Set (if you're patient) and play the zooms. New images can be saved and loaded as DFT files. Julia Set There's a Julia Set for every point of the Mandelbrot Set, connected from if the set, disconnected otherwise. You can select a point with the "Use Mandelbrot u" setting, or use a cursor. You can also make Julia Sets of different complex math functions and zoom into them. The default is the Mandelbrot Set function z'=z^2+u, but many other functions are available including complex SIN and COS. Most have ready made images (with comments) stored as DFT files. You have all the same plot and play options as with the Mandelbrot Set menu. Logistic Iterations Iterations of the formula x'=4Lx(1-x) for x in {0-1}. Pick a Lambda value (0-1), start with a value of x, and use the formula to get a new value of x. Then use that value of x to get a new value. And so on. Each horizontal line of the graph shows the results for a lambda value, and the dots show the x-values jumping back and forth. Now imagine laying a keyboard along the base of the graph, and let the x points jump back and forth along the keyboard making notes. (Like Donald Duck in Brasil!) The results are suprising interesting musically, though everything depends on the lambda point. Try places that are chaotic, but not TOO chaotic. Of course you can zoom and save. Graph Type in any function y=f(x) and create a musical graph (as well as a visual one). Just imagine laying a keyboard along the y-axis, and sounding the note as well as plotting the point, with the x-axis as time. We graph functions to see patterns. But the ear is also adept at recognizing patterns, so I think this is a valid approach. This uses the same math routines that System\Calculator uses, so complex formulae are possible. It's pretty slow. Scales Simple multi-track scales up and down, with shifting tonality and tempo. The results are pretty entertaining. SCALES.MSQ is an example. Cantor Canon This is a very cool option, I think from a Dewdney Computer Recreations column in Scientific American, but I can't find the source. First make a track, either with a Compose option, or record something from your keyboard with Tape\Record, or use Edit\Notes. Keep it short, just a few notes will do. A Cantor Canon then builds a copy on top of each note of the original, scaling note and tempo to match. And then a copy on top of each note of that. And so on. Play with the time and tempo settings if the notes are too short. This is a musical analog of a Cantor Dust fractal, with complete self-similarity, a sort of fractal fugue. As always, there are lots of options. CANON.MSQ is an example. Cellular Automata Nada. These don't work, but they're Markov Chain all good ideas for algo-comp! L-Sys Tree IFS Transforms Turing Machine Travesty Data Table ANALYZE Analyze tracks, not yet implemented. ------- Statistics Nada. Distribution Frequency HELP I wish! This is it. ---- Topics Nada. Index Contents The Files ----------- Files below the dotted line are SOURCE files that can be deleted if you don't want them. Any .TBB files that appear in your directory after using MSQ are scrap files that can be deleted. (MSQ should delete them automatically when it shuts down.) MSQ.EXE DOS executable MSQ.PIF run MSQ full screen in Win31 (if MIDI driver allows) MSQ.ICO a generic Win31 icon (swiped from ICOLIB) MSQ2MID.EXE utility to convert MSQ files to MID *.DFT image files (and settings) for Compose fractals *.LOG data for last fractal calc *.MSQ saved MIDI sequences *.PAL 16 color VGA color palettes *.TBB scrap files that should be deleted on exit LOGISTIC.DFT f(x)=4Lx(1-x) Logistic Iterations default image MSET.DFT f(z)=z^2+u Mandelbrot Set default image COSZ.DFT f(z)=n*cos(z)+u Julia Set default image COSHZ.DFT f(z)=n*cosh(z)+u Julia Set default image EXPZ.DFT f(z)=n*e^z+u Julia Set default image NZZ.DFT f(z)=n*z^z+u Julia Set default image SINZ.DFT f(z)=n*sin(z)+u Julia Set default image SINHZ.DFT f(z)=n*sinh(z)+u Julia Set default image Z2.DFT f(z)=n*z^2+u Julia Set default image ZZZN.DFT f(z)=z^z+z^n+u Julia Set default image SCALES.MSQ Compose\Scales sample sequence CANON.MSQ Compose\Cantor_Canon sample sequence DEFAULT.PAL default 16 color VGA palette for System\Colors\Default PRINTER.PAL ok screen dumps on Epson compatible dot printer README.TXT this file TBVAULT.TXT about Treebeard's Basic Vault ------------ MSQ.MAK file list for PDS/QB MSQ.BAS source: main module MSUP2.BAS source: support routines MF4.BAS source: calc, eval, clock, and other frame goodies MSEQ1.BAS source: working routines, menus, etc MSEQ2.BAS source: edit, analyze, goto, mark routines MSEQ3.BAS source: compose routines MSEQ3B.BAS source: more compose MSEQ4.BAS source: play/record routines MSEQ4B.BAS source: more play/record MFRAME.BI include files of shared and common stuff SFRAMELT.BI MSUP.BI MIDI.BI MSEQ1.BI MSEQ2.BI MSEQ3.BI MSEQ3LOC.BI MSEQ4.BI MSEQ4LOC.BI XQB.BAT batch file to start PDS and load code MAKE.BAT batch file to compile and link from DOS prompt MSQ.LNK LINK response file called by MAKE.BAT MSQ2MID.BAS source to convert MSQ files to MID Guidance from --------------- Conger, C Programming For MIDI, 1988. Conger, MIDI Sequencing in C, 1989. Dewdney, Computer Recreations columns in SciAm. Reprinted in The Armchair Universe, The Magic Machine, etc. Peitgen and Saupe, The Science of Fractal Images, 1988. Pickover, Computers and the Imagination, 1991. Pickover, Mazes for the Mind, 1992. Music Quest, MIDI Co-Processor Card Technical Reference, 1988. Roland Corporation, MPU-401 Technical Reference Manual, 1988. Sprott, Numerical Recipies: Routines and Examples in Basic, 1991. Voyetra Technologies, OP-4001 Technical Reference Manual, 1987. Winsor and DeLisa, Computer Music in C, 1991. various articals in old Byte, Keyboard, and Electronic Musician magazines. Conditions ------------ This program and source code are yours to use and modify as you will, but they are offered as freeware with no warranty whatsoever. Give me credit, but do not distribute any changes under my name, or attribute such changes to me in any way. You're on your own! Send comments and fixes to: Marc Kummel aka Treebeard mkummel@rain.org http://www.rain.org/~mkummel/ For more interesting Basic software with source code, check out Treebeard's Basic Vault at http://www.rain.org/~mkummel/basic/