Changeset 776

Show
Ignore:
Timestamp:
02/08/09 17:41:34 (4 years ago)
Author:
cmennie@…
Message:

Possible midi out support added to CoreMIDI stuff. Having never seen CoreMIDI
before, nor ever owning a mac, I'm just guessing at this point.

Location:
branches/midi_out/libs/hydrogen
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/midi_out/libs/hydrogen/include/hydrogen/IO/CoreMidiDriver.h

    r733 r776  
    3333#include <CoreMidi/CoreMidi.h> 
    3434#include <hydrogen/IO/MidiInput.h> 
     35#include <hydrogen/IO/MidiOutput.h> 
    3536 
    3637namespace H2Core 
     
    4950        virtual std::vector<QString> getOutputPortList(); 
    5051         
    51         virtual void handleQueueNote(Note* pNote) {} 
    52         virtual void handleQueueAllNoteOff() {} 
     52        virtual void handleQueueNote(Note* pNote); 
     53        virtual void handleQueueAllNoteOff(); 
    5354 
    5455        MIDIClientRef  h2MIDIClient; 
     
    5758 
    5859        MIDIPortRef h2InputRef; 
     60        MIDIPortRef h2OutputRef; 
     61        MIDIEndpointRef cmH2Dst; 
    5962 
    6063}; 
  • branches/midi_out/libs/hydrogen/src/IO/coremidi_driver.cpp

    r127 r776  
    103103        err = MIDIClientCreate ( CFSTR( "h2MIDIClient" ), NULL, NULL, &h2MIDIClient ); 
    104104        err = MIDIInputPortCreate ( h2MIDIClient, CFSTR( "h2InputPort" ), midiProc, this, &h2InputRef ); 
     105        err = MIDIOutputPortCreate ( h2MIDIClient, CFSTR( "h2OutputPort" ), midiProc, this, &h2OutputRef ); 
    105106} 
    106107 
     
    144145                CFRelease ( H2MidiNames ); 
    145146        } 
     147         
     148        int n = MIDIGetNumberOfDestinations(); 
     149        if (n > 0) { 
     150                cmH2Dst = MIDIGetDestination(0); 
     151        } 
     152 
     153        if (cmH2Dst != NULL) { 
     154                CFStringRef H2MidiNames; 
     155                 
     156                MIDIObjectGetStringProperty(cmH2Dst, kMIDIPropertyName, &H2MidiNames); 
     157                CFStringGetCString(pname, name, sizeof(name), 0); 
     158                //MIDIPortConnectSource ( h2OutputRef, cmH2Dst, NULL ); 
     159                CFRelease( H2MidiNames ); 
     160        } 
    146161} 
    147162 
     
    153168        err = MIDIPortDisconnectSource( h2InputRef, cmH2Src ); 
    154169        err = MIDIPortDispose( h2InputRef ); 
     170        //err = MIDIPortDisconnectSource( h2OutputRef, cmH2Dst ); 
     171        err = MIDIPortDispose( h2OutputRef ); 
    155172        err = MIDIClientDispose( h2MIDIClient ); 
    156173} 
     
    186203                CFRelease( H2MidiNames ); 
    187204        } 
     205                 
    188206        return cmPortList; 
     207} 
     208 
     209void CoreMidiDriver::handleQueueNote(Note* pNote) 
     210{        
     211        if (cmH2Dst == NULL ) { 
     212                ERRORLOG( "cmH2Dst = NULL " ); 
     213                return; 
     214        } 
     215 
     216        int channel = pNote->get_instrument()->get_midi_out_channel(); 
     217        if (channel < 0) { 
     218                return; 
     219        } 
     220                 
     221        int key = pNote->get_instrument()->get_midi_out_note(); 
     222        int velocity = pNote->get_velocity() * 127; 
     223         
     224        MIDIPacketList packetList; 
     225        packetList.numPackets = 1; 
     226         
     227        packetList.packet.timeStamp = 0; 
     228        packetList.packet.length = 3; 
     229        packetList.packet.data[0] = 0x80 | channel; 
     230        packetList.packet.data[1] = key; 
     231        packetList.packet.data[2] = velocity; 
     232         
     233         
     234        MIDISend(h2OutputRef, cmH2Dst, &packetList); 
     235         
     236        packetList.packet.data[0] = 0x90 | channel; 
     237        packetList.packet.data[1] = key; 
     238        packetList.packet.data[2] = velocity; 
     239         
     240        MIDISend(h2OutputRef, cmH2Dst, &packetList); 
     241} 
     242 
     243void CoreMidiDriver::handleQueueAllNoteOff() 
     244{ 
     245        if (cmH2Dst == NULL ) { 
     246                ERRORLOG( "cmH2Dst = NULL " ); 
     247                return; 
     248        } 
     249         
     250        InstrumentList *instList = Hydrogen::get_instance()->getSong()->get_instrument_list(); 
     251                 
     252        unsigned int numInstruments = instList->get_size(); 
     253        for (int index = 0; index < numInstruments; ++index) { 
     254                Instrument *curInst = instList->get(index); 
     255         
     256                int channel = curInst->get_midi_out_channel(); 
     257                if (channel < 0) { 
     258                        continue; 
     259                } 
     260                int key = curInst->get_midi_out_note(); 
     261         
     262                MIDIPacketList packetList; 
     263                packetList.numPackets = 1; 
     264         
     265                packetList.packet.timeStamp = 0; 
     266                packetList.packet.length = 3; 
     267                packetList.packet.data[0] = 0x80 | channel; 
     268                packetList.packet.data[1] = key; 
     269                packetList.packet.data[2] = 0;   
     270         
     271                MIDISend(h2OutputRef, cmH2Dst, &packetList); 
     272         
     273        } 
    189274} 
    190275