| 34 | AmdtpMidiPort::AmdtpMidiPort(std::string name, |
---|
| 35 | enum E_Direction direction, |
---|
| 36 | int position, |
---|
| 37 | int location, |
---|
| 38 | enum E_Formats format, |
---|
| 39 | int type) |
---|
| 40 | : MidiPort(name, direction), |
---|
| 41 | AmdtpPortInfo(name, position, location, format, type) |
---|
| 42 | , m_countdown(0) |
---|
| 43 | { |
---|
| 44 | m_ringbuffer=freebob_ringbuffer_create(m_buffersize * getEventSize()); |
---|
| 45 | |
---|
| 46 | if(!m_ringbuffer) { |
---|
| 47 | debugFatal("Could not allocate ringbuffer\n"); |
---|
| 48 | m_buffersize=0; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | AmdtpMidiPort::~AmdtpMidiPort() { |
---|
| 54 | if (m_ringbuffer) freebob_ringbuffer_free(m_ringbuffer); |
---|
| 55 | |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | /** |
---|
| 59 | * The problem with MIDI ports is that there is no guaranteed availability of data. |
---|
| 60 | * This function will return true if: |
---|
| 61 | * (1) there is a byte ready in the buffer |
---|
| 62 | * (2) we are allowed to send a byte |
---|
| 63 | * |
---|
| 64 | * it will also assume that you actually are sending a byte, and it will reset |
---|
| 65 | * the countdown |
---|
| 66 | * |
---|
| 67 | * note on (2): the midi over 1394 spec limits the speed of sending midi data bytes. |
---|
| 68 | * For every (time muxed) channel, you can send only one midi byte every |
---|
| 69 | * 320 microseconds. The packet rate is 8000pkt/sec, or 125us. Therefore |
---|
| 70 | * we wait (at least) two packets before sending another byte. This comes |
---|
| 71 | * down to 375us, so there is a slight limiting of the bandwidth. |
---|
| 72 | * |
---|
| 73 | * \todo fix the too long delay (375us instead of 320us) |
---|
| 74 | * |
---|
| 75 | * @return true if you can send a midi byte |
---|
| 76 | */ |
---|
| 77 | bool AmdtpMidiPort::canSend() { |
---|
| 78 | bool byte_present_in_buffer; |
---|
| 79 | assert(m_ringbuffer); |
---|
| 80 | |
---|
| 81 | byte_present_in_buffer=(freebob_ringbuffer_read_space(m_ringbuffer)>=sizeof(char)); |
---|
| 82 | |
---|
| 83 | if(byte_present_in_buffer && (m_countdown < 0)) { |
---|
| 84 | m_countdown=2; |
---|
| 85 | return true; |
---|
| 86 | } |
---|
| 87 | return false; |
---|
| 88 | } |
---|