Open Sound System
|Do you have problems with sound/audio application development? Don't panic! Click here for help!|
int mode = MIDI_MODE_TRADITIONAL or MIDI_MODE_TIMED or MIDI_MODE_ALTERNATIVE
ioctl(fs, SNDCTL_MIDI_SETMODE, &mode);
The above code fragment lacks all error checks for clarity. Real world applications must always check for the errors and handle them as described below. Also most OSS ioctl calls will return information in the argument variable and it's usually necessary to check it too.
Traditionally MIDI ports have been simple serial communication devices with no timing capability. In this mode (MIDI_MODE_TRADITIONAL) everything written to the /dev/midi device will be sent out as quickly of possible.
OSS 4.0 introduces a new timed mode (MIDI_MODE_TIMED) which permits driver level timing. The application writes data to the MIDI device as packets which contain the transmit time (midi clocks) in addition to the actual bytes to be sent. Instead of sending everything out immediately the driver delays the transmission until the exact moment given by the application. This permits very precise timing which is not affected by possible variations in the system load. Also input data will be received as packets with the exact reception time.
See the Using the timed mode MIDI interface section for more info about using the timed mode.
In addition to the MIDI_MODE_TRADITIONAL and MIDI_MODE_TIMED modes there is also a third mode (MIDI_MODE_ALTERNATIVE). However this mode is reserved for future purposes. It's not defined and must not be used in applications.
This call must be made immediately after opening the MIDI device (before doing anything else). Changing the mode later will cause unpredictable problems.
This call is new in OSS 4.0. No earlier OSS versions support it (errno=EINVAL will be returned. In this case the traditional mode will be used.
The return value from the OSS ioctl calls will be -1 if a fatal error occurred. Other values mean that the ioctl call was more or less successful. However in most cases the application must check the value returned in the argument to see what was the accepted value.
Please see the Possible error codes (errno) returned by OSS calls section for more info about the error codes returned by OSS.