|
| 1 | +# |
| 2 | +# This file is part of usb-protocol. |
| 3 | +# |
| 4 | +""" |
| 5 | + Descriptors for USB MIDI Class Devices |
| 6 | +
|
| 7 | + [Midi10] refers to "Universal Serial Bus Device Class Definition for MIDI Devices", Release 1.0, November 1, 1999 |
| 8 | +""" |
| 9 | + |
| 10 | +from enum import IntEnum |
| 11 | + |
| 12 | +from .standard import StandardDescriptorNumbers |
| 13 | + |
| 14 | + |
| 15 | +class MidiStreamingInterfaceDescriptorSubtypes(IntEnum): |
| 16 | + # As defined in [Midi10], A.1 |
| 17 | + MS_DESCRIPTOR_UNDEFINED = 0x00 |
| 18 | + MS_HEADER = 0x01 |
| 19 | + MIDI_IN_JACK = 0x02 |
| 20 | + MIDI_OUT_JACK = 0x03 |
| 21 | + ELEMENT = 0x04 |
| 22 | + |
| 23 | + |
| 24 | +class MidiStreamingEndpointDescriptorSubtypes(IntEnum): |
| 25 | + # As defined in [Midi10], A.2 |
| 26 | + DESCRIPTOR_UNDEFINED = 0x00 |
| 27 | + MS_GENERAL = 0x01 |
| 28 | + |
| 29 | + |
| 30 | +class MidiStreamingJackTypes(IntEnum): |
| 31 | + # As defined in [Midi10], A.3 |
| 32 | + JACK_TYPE_UNDEFINED = 0x00 |
| 33 | + EMBEDDED = 0x01 |
| 34 | + EXTERNAL = 0x02 |
| 35 | + |
| 36 | + |
| 37 | +# As defined in [Midi10], Table 6-1 |
| 38 | +StandardMidiStreamingInterfaceDescriptor = DescriptorFormat( |
| 39 | + "bLength" / construct.Const(9, construct.Int8ul), |
| 40 | + "bDescriptorType" / DescriptorNumber(DescriptorTypes.INTERFACE), |
| 41 | + "bInterfaceNumber" / DescriptorField(description="ID of the streaming interface"), |
| 42 | + "bAlternateSetting" / DescriptorField(description="alternate setting number for the interface", default=0), |
| 43 | + "bNumEndpoints" / DescriptorField(description="Number of data endpoints used (excluding endpoint 0). Can be: 0 (no data endpoint); 1 (data endpoint); 2 (data + explicit feedback endpoint)", default=0), |
| 44 | + "bInterfaceClass" / DescriptorNumber(AudioInterfaceClassCode.AUDIO), |
| 45 | + "bInterfaceSubClass" / DescriptorNumber(AudioInterfaceSubclassCodes.MIDI_STREAMING), |
| 46 | + "bInterfaceProtocol" / DescriptorNumber(0), |
| 47 | + "iInterface" / DescriptorField(description="index of a string descriptor describing this interface (0 = unused)", default=0) |
| 48 | +) |
| 49 | + |
| 50 | +# As defined in [Midi10], Table 6-2 |
| 51 | +ClassSpecificMidiStreamingInterfaceHeaderDescriptor = DescriptorFormat( |
| 52 | + "bLength" / construct.Const(7, construct.Int8ul), |
| 53 | + "bDescriptorType" / DescriptorNumber(AudioClassSpecificDescriptorTypes.CS_INTERFACE), |
| 54 | + "bDescriptorSubtype" / DescriptorNumber(AudioClassSpecificACInterfaceDescriptorSubtypes.HEADER), |
| 55 | + "bcdADC" / DescriptorField(description="Midi Streaming Class specification release version", default=1.0), |
| 56 | + "wTotalLength" / DescriptorField(description="Total number of bytes of the class-specific MIDIStreaming interface descriptor. Includes the combined length of this descriptor header and all Jack and Element descriptors."), |
| 57 | +) |
| 58 | + |
| 59 | +# As defined in [Midi10], Table 6-3 |
| 60 | +MidiInJackDescriptor = DescriptorFormat( |
| 61 | + "bLength" / construct.Const(6, construct.Int8ul), |
| 62 | + "bDescriptorType" / DescriptorNumber(AudioClassSpecificDescriptorTypes.CS_INTERFACE), |
| 63 | + "bDescriptorSubtype" / DescriptorNumber(MidiStreamingInterfaceDescriptorSubtypes.MIDI_IN_JACK), |
| 64 | + "bJackType" / DescriptorField(description="see MidiStreamingJackTypes"), |
| 65 | + "bJackID" / DescriptorField(description="Constant uniquely identifying the MIDI IN Jack within the USB-MIDI function"), |
| 66 | + "iJack" / DescriptorField(description="index of a string descriptor describing this jack (0 = unused)", default=0) |
| 67 | +) |
| 68 | + |
| 69 | +# As defined in [Midi10], Table 6-4 |
| 70 | +MidiOutJackDescriptorHead = DescriptorFormat( |
| 71 | + "bLength" / DescriptorField(description="Size of this descriptor, in bytes: 6+2*p"), |
| 72 | + "bDescriptorType" / DescriptorNumber(AudioClassSpecificDescriptorTypes.CS_INTERFACE), |
| 73 | + "bDescriptorSubtype" / DescriptorNumber(MidiStreamingInterfaceDescriptorSubtypes.MIDI_OUT_JACK), |
| 74 | + "bJackType" / DescriptorField(description="see MidiStreamingJackTypes"), |
| 75 | + "bJackID" / DescriptorField(description="Constant uniquely identifying the MIDI IN Jack within the USB-MIDI function"), |
| 76 | + "bNrInputPins" / DescriptorField(description="Number of Input Pins of this MIDI OUT Jack: p", default=1) |
| 77 | +) |
| 78 | + |
| 79 | +MidiOutJackDescriptorElement = DescriptorFormat( |
| 80 | + "baSourceID" / construct.Int8ul, # ID of the Entity to which the first Input Pin of this MIDI OUT Jack is connected |
| 81 | + "BaSourcePin" / construct.Int8ul, #Output Pin number of the Entity to which the first Input Pin of this MIDI OUT Jack is connected |
| 82 | +) |
| 83 | + |
| 84 | +MidiOutJackDescriptorFoot = DescriptorFormat( |
| 85 | + "iJack" / DescriptorField(description="index of a string descriptor describing this jack (0 = unused)", default=0) |
| 86 | +) |
| 87 | + |
| 88 | +# As defined in [Midi10], Table 6-6 |
| 89 | +StandardMidiStreamingBulkDataEndpointDescriptor = DescriptorFormat( |
| 90 | + "bLength" / construct.Const(9, construct.Int8ul), |
| 91 | + "bDescriptorType" / DescriptorNumber(DescriptorTypes.ENDPOINT), |
| 92 | + "bEndpointAddress" / DescriptorField(description="The address of the endpoint, use USBDirection.*.from_endpoint_address()"), |
| 93 | + "bmAttributes" / DescriptorField(description="D1..0: transfer type (10=bulk), D3..2: synchronization type (00=no sync);", default=USBTransferType.BULK | USBSynchronizationType.NONE | USBUsageType.DATA), |
| 94 | + "wMaxPacketSize" / DescriptorField(description="Maximum packet size this endpoint is capable of", default=512), |
| 95 | + "bInterval" / DescriptorField(description="Interval for polling endpoint for data transfers expressed in milliseconds. This field is ignored for bulk endpoints. Must be set to 0", default=0), |
| 96 | + "bRefresh" / DescriptorField(description="must be set to 0", default=0), |
| 97 | + "bSynchAddress" / DescriptorField(description="The address of the endpoint used to communicate synchronization information if required by this endpoint. Must be set to 0", default=0) |
| 98 | +) |
| 99 | + |
| 100 | +# As defined in [Midi10], Table 6-7 |
| 101 | +ClassSpecificMidiStreamingBulkDataEndpointDescriptorHead = DescriptorFormat( |
| 102 | + "bLength" / DescriptorField(description="Size of this descriptor, in bytes: 4+n"), |
| 103 | + "bDescriptorType" / DescriptorNumber(AudioClassSpecificDescriptorTypes.CS_ENDPOINT), |
| 104 | + "bDescriptorSubtype" / DescriptorField(description="see MidiStreamingEndpointDescriptorSubtypes", default=MidiStreamingEndpointDescriptorSubtypes.MS_GENERAL), |
| 105 | + "bNumEmbMIDIJack" / DescriptorField(description="Number of Embedded MIDI Jacks: n", default=1) |
| 106 | +) |
| 107 | + |
| 108 | +ClassSpecificMidiStreamingBulkDataEndpointDescriptorElement = DescriptorFormat( |
| 109 | + "baAssocJackID" / construct.Int8ul # ID of the embedded eack that is associated with this endpoint |
| 110 | +) |
0 commit comments