ftp.nice.ch/peanuts/GeneralData/Documents/NeXT/MIDIDriver.tar.gz#/MIDIDriver/Introduction.rtf

This is Introduction.rtf in view mode; [Download] [Up]

paperh22175 margl-907 margr0 margt0 margb0 {fonttblf0fswiss Helvetica;f1froman Times;f2fmodern Courier;f3ftech Symbol;f4froman Palantino;}fi0 ri0 ql sb0 f1 fs24 Release 2.0  Copyright f3 'e3f1 1991 by NeXT Computer, Inc.  All Rights Reserved.

fs56 f1 ql ri1007 li2116 fi0 MIDI and the MIDI Driver
fs16 











fs56 pard s1 li100 fi0 ri1007 ql b fs36 fs16 fs36 Introduction
fs16 
fs36 s25 li1108 fi-1007 fi0 fs36 fs16 

fs36 About This Document
fs16 
fs36 pard s3 li2116 fi0 ri1007 ql tx2116 tx2620 tx3124 tx3628 b0 fs28 fs16 fs28 This document consists of an introduction to MIDI and a specification of the NeXT MIDI driver C functions.  The sections 'aaWhat is MIDI?'ba and 'aaConnecting MIDI Devices'ba are intended for all users of MIDI.  Programmers should additionally read 'aaNeXT Software Support for MIDI'ba to determine whether they'27ll use the Music Kitf3 'd4f1  or the driver C functions.  Those planning to use the driver C functions should read 'aaThe MIDI Data Format,'ba 'aaMIDI Driver Overview,'ba and 'aaMIDI Driver C Functions.'ba
fs16 
fs28 pard s25 li1108 fi0 ri1007 ql b fs36 fs16 



fs36 What is MIDI?
fs16 
fs36 pard s3 li2116 fi0 ri1007 ql tx2116 tx2620 tx3124 tx3628 b0 fs28 fs16 fs28 MIDI, the Musical Instrument Digital Interface, defines a software format and a hardware standard for exchanging information among electronic musical instruments (such as synthesizers, samplers, digital pianos, and guitar or wind controllers) as well as other devices (such as computers, sequencers, mixers, signal processors, and even stage lighting).  Originally designed to capture the performance gestures of a keyboard player, MIDI normally transmits keyboard-oriented information, such as which key the performer depressed and with what velocity, or which button or slider was adjusted on a synthesizer'27s control panel.  This sort of data is much more compact and more easily edited than the data in a digital audio recording of the same performance.  Unlike audio data, MIDI data can easily be used to control other instruments or to create a printed score (using a music notation application).
fs16 
fs28 fs16 fs28 By hooking a MIDI instrument to a NeXTf3 'd4f1  computer, you can 'aaplay'ba the built-in DSP as a sound synthesizer.  You can also create an automated performance by editing music data files and sending the data to external MIDI synthesizers.  The demonstration program b /NextDeveloper/Demos/Ensemble b0 lets you explore these features, among others.
fs16 
fs28 fs16 fs28 Non-musical applications could also be written to exploit MIDI'27s real-time control.  For example, with the mouse, a user can move only one graphical slider at a time; but with an external MIDI device, each finger could control a different slider independently.  Similarly, a group of users could operate different controls simultaneously, perhaps to play a game.
fs16 
fs28 pard s25 li1108 fi0 ri1007 ql b fs36 fs16 



fs36 Connecting MIDI Devices
fs16 
fs36 pard s3 li2116 fi0 ri1007 ql tx2116 tx2620 tx3124 tx3628 b0 fs28 fs16 fs28 You can connect MIDI instruments to either of a NeXT computer'27s serial ports, using an external device known as a MIDI interface.  The instruments connect to the MIDI interface (or to each other) with standard MIDI cables, available at most music stores.  The MIDI interface adapts these cables'27 unidirectional 5-pin DIN connectors to the serial port'27s bidirectional mini-DIN connector.  Any number of instruments can be connected to a serial port through the interface, and the two ports can be used simultaneously (whether by the same application or by two different ones).  A single serial port can receive and transmit MIDI data at the same time.
fs16 
fs28 fs16 fs28 Which MIDI interface to use depends on which computer you have.  While the older 68030-based NeXT computer has RS-422 serial ports, the 68040-based computers'd0the NeXTstation, NeXTstation Color, and NeXTcube'd0have RS-423 ports (which are compatible with RS-232, and which support hardware flow control for modems).  MIDI interfaces designed for Macintosh computers work with the 68030-based NeXT computer, using a standard Macintosh serial cable, since the Macintosh also has RS-422 ports.  These interfaces can be obtained at most music stores.  Some interfaces include the cable that connects the interface to the computer.
fs16 
fs28 fs16 fs28 Most Macintosh-style interfaces don'27t work with NeXT'27s 68040-based computers, however.  Typically, these interfaces exhibit the symptom of not transferring any MIDI data, or transferring it in only one direction (in but not out, or vice versa).  One Macintosh-style interface that is known to work is the Opcode Studio 3.  The appropriate cable for connecting it to 68040-based NeXT computers is described in the b zsb0  UNIX manual page (under 'aaNeXT 68040 to Some RS-422 Devices'ba), and is available from Computer Cables and Devices at (203) 287-0197.  Opcode Systems may provide other solutions, including the modification of existing Pro Plus interfaces to work with 68040-based NeXT computers using standard serial cables.  (Contact Opcode Systems at (415) 369-8131.)  Rupert Nieberle in Berlin (phone:  49-30-618-7765) manufactures two MIDI interfaces that are compatible with the 68040-based machines, using standard cables.
fs16 
fs28 fs16 fs28 The musical instrument must be set up correctly for MIDI communication to work as expected.  Because MIDI is a unidirectional protocol, there'27s no means for an application to verify that the external device is receiving the MIDI data that the application sends.  Thus the user is responsible for ensuring that the configuration is correct.  For instructions on setting up the MIDI device, see the owner'27s manual for that device.
fs16 
fs28 fs16 fs28 In particular, note that most MIDI commands are sent on specific 'aachannels.'ba  Unlike the left and right channels of analog audio signals, MIDI channels don'27t use separate cables, but instead are encoded in the MIDI data itself.  The sixteen MIDI channels are used for sending separate streams of commands to different synthesizers on a single MIDI network, or to the distinct sound-generating units within a single multi-timbral synthesizer (such as the NeXT computer's DSP, as used by the Music Kit).  There'27s no MIDI command that asks a device to start using a certain MIDI channel.  Instead, the user must manually set the MIDI device to transmit and receive on the channels expected by the software.  A typical default is to transmit and receive on channel 1.
fs16 
fs28 pard s25 li1108 fi0 ri1007 ql b fs36 fs16 



fs36 NeXT Software Support for MIDI
fs16 
fs36 pard s3 li2116 fi0 ri1007 ql tx2116 tx2620 tx3124 tx3628 b0 fs28 fs16 fs28 There are two levels of programming support for MIDI in the NeXT system software:
fs16 
fs28 pard s13 li2620 fi-503 ri1007 ql tx2620 tx3124 tx3628 tx4132 fs16 fs28 'b7	The MIDI driver is a loadable Mach device driver that controls the flow of MIDI data to and from the serial ports.  The MIDI library,b  /usr/lib/libmidi.ab0 , contains C functions for direct control of the MIDI driver.  Programming at this level'd0the MIDI driver C functions'd0gives you the greatest amount of control over the buffering and timing of MIDI data.  However, this control comes at the expense of programming simplicity.
fs16 
fs28 fs16 fs28 'b7	At a higher level, the Music Kit includes an Objective-C language class called Midi that provides an object-oriented interface to the MIDI driver.  Programming at this level is much easier, because the Midi object insulates you from details of the driver, and because the MIDI data is parsed and interpreted for you.  This level also lets you take advantage of Music Kit features such as the automatic translation of MIDI data into Scorefile commands or into DSP sound synthesis instructions.
fs16 
fs28 pard s3 li2116 fi0 ri1007 ql tx2116 tx2620 tx3124 tx3628 fs16 fs28 Generally, the Music Kit is the recommended approach.  The Music Kit'27s Midi class will almost always give you all the functionality you need, without adding any noticeable delay to the MIDI processing provided by the driver.  However, if you'27re not using the Music Kit for anything else, and you'27re more concerned with maximum efficiency than programming ease, you may want to use the driver'27s C functions instead of the Midi class'27s Objective-C methods.  The functions also provide some features that the Midi class doesn'27t'd0for example, you can manage the size of the MIDI data queue, manipulate the driver'27s timer, and filter out a few more kinds of MIDI commands'd0but you'27ll rarely need these features.
fs16 
fs28 fs16 fs28 For information on MIDI support in the Music Kit, see 'aaSound and Music Overview'ba and 'aaMusic Performance'ba in i Sound, Music, and Signal Processing:  Concepts.  i0 In i Sound, Music, and Signal Processing:  Referencei0 , see the Midi Class Specification, as well as the Music Kit C Functions and the ScoreFile reference.  The programming examples in b /NextDeveloper/Examples/MusicKitb0  are helpful, particularly those whose names begin with 'aaMidi.'ba  For a more advanced example, see b Ensembleb0  in the same directory.
fs16 
fs28 fs16 fs28 The rest of this document contains information that'27s useful for programming with the MIDI driver C functions.  The sample C programs inb  /NextDeveloper/Examples/MidiDriverb0  illustrate some of the functions documented here.  Information can also be gleaned from the header files in b /usr/include/midib0 .
fs16 
fs28 pard s25 li1108 fi0 ri1007 ql b fs36 fs16 



fs36 The MIDI Data Format
fs16 
fs36 pard s3 li2116 fi0 ri1007 ql tx2116 tx2620 tx3124 tx3628 b0 fs28 fs16 fs28 If you use the MIDI driver functions rather than the Music Kit, you'27ll be examining MIDI data as hexadecimal values, so you'27ll need to understand the MIDI data format.  Read this section for a synopsis of the data format, if you'27re not already familiar with the MIDI specification.
fs16 
fs28 fs16 fs28 MIDI data consists of commands sent in an asynchronous serial stream at 31.25 kBaud.  The data is transmitted in ten-bit bytes, but the first and last bits of each byte are start and stop bits, added by the transmitting device and stripped off by the receiving device.  Thus, MIDI commands are considered to consist of eight-bit bytes.  A typical MIDI command contains:
fs16 
fs28 pard s13 li2620 fi-503 ri1007 ql tx2620 tx3124 tx3628 tx4132 fs16 fs28 'b7	Onei  i0 Status byte (whose most significant bit is set to 1).  The Status byte defines a type of command, such as Note On or Pitch Bend.
fs16 
fs28 fs16 fs28 'b7	Zero, one, or two Data bytes (each having its most significant bit set to 0).  Data bytes contain values applied by the command, such as 'aakey number'ba and 'aavelocity,'ba or 'aaamount of pitch bend.'ba  The type of command, specified by the preceding Status byte, determines how many Data bytes are expected.
fs16 
fs28 pard s3 li2116 fi0 ri1007 ql tx2116 tx2620 tx3124 tx3628 fs16 fs28 There are two exceptions to the above pattern:
fs16 
fs28 pard s13 li2620 fi-503 ri1007 ql tx2620 tx3124 tx3628 tx4132 fs16 fs28 'b7	The Status byte may be omitted, in which case the type of command is given by the most recent Status byte.  This condition is called Running Status.
fs16 
fs28 fs16 fs28 'b7	The Status byte F0 (hexadecimal) is the special System Exclusive command, which is followed by a Data byte identifying a particular manufacturer, and any number of subsequent Data bytes whose meaning the manufacturer is free to determine.  Only that manufacturer'27s instruments are expected to respond to the System Exclusive command.
fs16 
fs28 pard s3 li2116 fi0 ri1007 ql tx2116 tx2620 tx3124 tx3628 fs16 fs28 Status bytes with hexadecimal values from 80 to EF are 'aachannel commands.'ba  These MIDI commands are sent on specific MIDI channels, as determined by the rightmost four bits of the Status byte.  Most MIDI devices can be configured to respond only to certain channels, making it possible for a single MIDI data stream to deliver different musical information to different devices simultaneously.
fs16 
fs28 fs16 fs28 Note that although MIDI bytes are classified as Status bytes or Data bytes, the term 'aaMIDI data'ba refers generically to everything in a stream of MIDI commands, both Status bytes and Data bytes.
fs16 
fs28 fs16 fs28 The file b <midi/midi_types.hb0 > includes a list of Status bytes and other standard MIDI definitions.  You can obtain the complete MIDI specification from the International MIDI Association at 11857 Hartsook St., North Hollywood, CA  91607, U.S.A.  For an introduction to the MIDI specification, including a summary of commands, see Gareth Loy'27s article 'aaMusicians Make a Standard:  The MIDI Phenomenon'ba in i Computer Music Journali0  Vol. 9, No. 4 (Winter 1985).
fs16 
fs28 pard s1 li100 fi0 ri1007 ql b fs36 fs16 



fs36  }

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.