1 /* 2 Copyright 1999, Be Incorporated. All Rights Reserved. 3 This file may be used under the terms of the Be Sample Code License. 4 */ 5 6 #ifndef _MIDI_DRIVER_H 7 #define _MIDI_DRIVER_H 8 9 #include <Drivers.h> 10 #include <module.h> 11 12 /* ----- 13 ioctl codes 14 ----- */ 15 16 /* the old opcodes are deprecated, and may or may not work 17 in newer drivers */ 18 enum { 19 B_MIDI_GET_READ_TIMEOUT = B_MIDI_DRIVER_BASE, 20 B_MIDI_SET_READ_TIMEOUT, 21 B_MIDI_TIMED_READ, 22 B_MIDI_TIMED_WRITE, 23 B_MIDI_WRITE_SYNC, 24 B_MIDI_WRITE_CLEAR, 25 B_MIDI_GET_READ_TIMEOUT_OLD = B_DEVICE_OP_CODES_END + 1, 26 B_MIDI_SET_READ_TIMEOUT_OLD 27 }; 28 29 /* the default timeout when you open a midi driver */ 30 #define B_MIDI_DEFAULT_TIMEOUT 1000000000000000LL 31 32 /* Usage: 33 To read, set "data" to a pointer to your buffer, and "size" to the 34 maximum size of this buffer. On return, "when" will contain the time 35 at which the data was received (first byte) and "size" will contain 36 the actual amount of data read. 37 Call ioctl(fd, B_MIDI_TIMED_READ, &midi_timed_data, sizeof(midi_timed_data)); 38 To write, set "when" to when you want the first byte to go out the 39 wire, set "data" to point to your data, and set "size" to the size 40 of your data. 41 Call ioctl(fd, B_MIDI_TIMED_WRITE, &midi_timed_data, sizeof(midi_timed_data)); 42 */ 43 typedef struct { 44 bigtime_t when; 45 size_t size; 46 unsigned char * data; 47 } midi_timed_data; 48 49 50 /* The MIDI parser returns the number of bytes that a message contains, given the */ 51 /* initial byte. For some messages, this is not known until the second byte is seen. */ 52 /* For such messages, a state > 0 is returned as well as some count > 0. When state */ 53 /* is > 0, you should call (*parse) for the next byte as well, which might modify */ 54 /* the returned message size. Message size will always be returned with the current */ 55 /* byte being counted as byte 1. A return of 0 means that the byte initiates a new */ 56 /* message. SysX is handled by returning max_size until the end or next initial message */ 57 /* is seen. So your loop looks something like: */ 58 /* 59 uint32 state = 0; // Only set this to 0 the first time you call the parser. 60 // preserve the 'state' between invocations of your read() hook. 61 int todo = 0; 62 unsigned char * end = in_buf+buf_size 63 unsigned char * out_buf = in_buf; 64 while (true) { 65 uchar byte = read_midi(); 66 if (!todo || state) { 67 todo = (*parser->parse)(&state, byte, end-out_buf); 68 } 69 if (todo < 1) { 70 unput_midi(byte); 71 } else { 72 *(out_buf++) = byte; 73 todo--; 74 } 75 if (todo < 1 || out_buf >= end) { 76 received_midi_message(in_buf, out_buf-in_buf); 77 todo = 0; 78 } 79 } 80 */ 81 82 #define B_MIDI_PARSER_MODULE_NAME "media/midiparser/v1" 83 84 typedef struct _midi_parser_module_info { 85 module_info minfo; 86 int (*parse)(uint32 * state, uchar byte, size_t max_size); 87 int _reserved_; 88 } midi_parser_module_info; 89 90 #define B_MPU_401_MODULE_NAME "generic/mpu401/v1" 91 92 enum { 93 B_MPU_401_ENABLE_CARD_INT = 1, 94 B_MPU_401_DISABLE_CARD_INT 95 }; 96 typedef struct _generic_mpu401_module { 97 module_info minfo; 98 status_t (*create_device)(int port, void ** out_storage, uint32 workarounds, void (*interrupt_op)(int32 op, void * card), void * card); 99 status_t (*delete_device)(void * storage); 100 status_t (*open_hook)(void * storage, uint32 flags, void ** out_cookie); 101 status_t (*close_hook)(void * cookie); 102 status_t (*free_hook)(void * cookie); 103 status_t (*control_hook)(void * cookie, uint32 op, void * data, size_t len); 104 status_t (*read_hook)(void * cookie, off_t pos, void * data, size_t * len); 105 status_t (*write_hook)(void * cookie, off_t pos, const void * data, size_t * len); 106 bool (*interrupt_hook)(void * cookie); 107 int _reserved_; 108 } generic_mpu401_module; 109 110 #endif 111