A conditional chunk, cdl (with a trailing space), is new in Level 2. It
lets one file serve several devices: an instrument can carry Level 1 chunks, Level 2
chunks and chunks for a proprietary device, and the parser keeps those that suit the
device. Sections 1.4.3, 2.5, 2.6 and 2.6.1 and the dls2.h header of
Downloadable Sounds Level 2.2. Level 1 devices do not know the chunk and skip
it, so it can sit safely in Level 1 lists.
The chunk
A cdl chunk is a list of operations. It can only be found in a list, and
defines the conditions under which the other chunks of that list are used; it is
recommended, not required, that it comes first in the list. It is an extendable
reverse Polish notation (RPN) program that queries the device.
<cdl-ck> → cdl( <Operation> [[<Operation>]…] )
<Operation> → USHORT Opcode; // an operator
| struct { USHORT Opcode; DLSID Query; } // DLS_CDL_QUERY, DLS_CDL_QUERY_SUPPORTED
| struct { USHORT Opcode; ULONG Constant; } // DLS_CDL_CONST
An operation is a 16-bit opcode, followed by a 16-byte
DLSID after a query opcode and by a
32-bit unsigned constant after DLS_CDL_CONST. A cdl chunk at
the top level of the form that the device fails means the whole file is ignored, and the
driver returns an error to the application; the specification recommends that sound
editors let the user ignore such an error to move sounds between devices.
Opcodes
The device keeps a stack of at least eight 32-bit words. X is the value on top of the
stack and Y the one below it; a binary operator pops both and pushes the result of the
C expression, a unary one pops X and pushes the result. Z is the constant after
DLS_CDL_CONST.
| Opcode | Name | Operation |
|---|---|---|
| 0x0001 | DLS_CDL_AND | X = X & Y |
| 0x0002 | DLS_CDL_OR | X = X | Y |
| 0x0003 | DLS_CDL_XOR | X = X ^ Y |
| 0x0004 | DLS_CDL_ADD | X = X + Y |
| 0x0005 | DLS_CDL_SUBTRACT | X = X - Y |
| 0x0006 | DLS_CDL_MULTIPLY | X = X * Y |
| 0x0007 | DLS_CDL_DIVIDE | X = X / Y |
| 0x0008 | DLS_CDL_LOGICAL_AND | X = X && Y |
| 0x0009 | DLS_CDL_LOGICAL_OR | X = X || Y |
| 0x000A | DLS_CDL_LT | X = (X < Y) |
| 0x000B | DLS_CDL_LE | X = (X <= Y) |
| 0x000C | DLS_CDL_GT | X = (X > Y) |
| 0x000D | DLS_CDL_GE | X = (X >= Y) |
| 0x000E | DLS_CDL_EQ | X = (X == Y) |
| 0x000F | DLS_CDL_NOT | X = !X |
| 0x0010 | DLS_CDL_CONST | X = Z: push the 32-bit constant |
| 0x0011 | DLS_CDL_QUERY | X = Query(DLSID): push the device’s answer; FALSE if the device does not support the query |
| 0x0012 | DLS_CDL_QUERY_SUPPORTED | X = QuerySupported(DLSID): push TRUE if the device supports the query, otherwise FALSE |
FALSE is all zeroes and TRUE all ones, but any non-zero value counts as TRUE, so
DLS_CDL_NOT must turn every non-zero value to zero. When the parser reaches
the end of the chunk it looks at the value on top of the stack: if it is true, the list
that holds the chunk is parsed; if false, the whole list is discarded. The explorer
reports a chunk that pops an empty stack, divides by zero, grows the stack beyond eight
words, has an opcode that is not defined or ends with an empty stack.
DLSID queries
All Level 2 devices must answer the first seven. Manufacturers can define more DLSIDs for their own features, which must be made by the UUID algorithm.
| Name | DLSID | Answer |
|---|---|---|
DLSID_SupportsDLS1 | 178F2F27-C364-11D1-A760-0000F875AC12 | TRUE if the device supports DLS Level 1 |
DLSID_SupportsDLS2 | F14599E5-4689-11D2-AFA6-00AA0024D8B6 | TRUE if the device supports DLS Level 2 |
DLSID_ManufacturersID | B03E1181-8095-11D2-A1EF-00600833DBD8 | the MIDI manufacturer’s ID in the low 24 bits |
DLSID_ProductID | B03E1182-8095-11D2-A1EF-00600833DBD8 | the product ID (manufacturer specific) |
DLSID_GMInHardware | 178F2F24-C364-11D1-A760-0000F875AC12 | TRUE if the device supports General MIDI in hardware |
DLSID_SampleMemorySize | 178F2F28-C364-11D1-A760-0000F875AC12 | the memory available in the device, in samples |
DLSID_SamplePlaybackRate | 2A91F713-A4BF-11D2-BBDF-00600833DBD8 | the true sample playback rate of the device in hertz |
DLSID_GSInHardware | 178F2F25-C364-11D1-A760-0000F875AC12 | defined in dls2.h: the device supports GS in hardware |
DLSID_XGInHardware | 178F2F26-C364-11D1-A760-0000F875AC12 | defined in dls2.h: the device supports XG in hardware |
Level 1 and Level 2 in one file
Section 2.6.1 shows how. A Level 1 device skips the chunk, so this one, in an
lart list, a rgn list or the lrgn list, keeps a
Level 2 device away from chunks written for Level 1:
cdl( DLS_CDL_QUERY(DLSID_SupportsDLS2) DLS_CDL_NOT )
The data for Level 2 goes in lar2 and rgn2 lists, which
Level 1 devices ignore, and a chunk that requires Level 2 isolates them further:
cdl( DLS_CDL_QUERY(DLSID_SupportsDLS2) )
A chunk at the beginning of the file establishes that the device supports either level:
cdl( DLS_CDL_QUERY(DLSID_SupportsDLS1) DLS_CDL_QUERY(DLSID_SupportsDLS2) DLS_CDL_LOGICAL_OR )
Two ways to write a file for both: separate sets of rgn2 chunks with their
own data, with a “not DLS Level 2” conditional chunk on the rgn chunks (the
two levels may then play different samples, a sampled filter sweep for Level 1 and a real
resonant filter for Level 2); or put the basic parameters in art1 and only
the Level 2 extensions in art2. Connections other than the fixed ones of the
routing table may be used in a
file only when guarded by a conditional chunk.
In the explorer
The Conditions tab lists every conditional chunk with its place, the program as opcodes, and the result of running it on a device that supports DLS Level 1 and Level 2 and no other query (the answer to an unsupported query is FALSE, as the specification says): whether its list is used on that device. The list a chunk guards is still shown in the other tabs, whatever the result.