[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/multimedia/kmid
From:       Pedro Lopez-Cabanillas <pedro.lopez.cabanillas () gmail ! com>
Date:       2010-08-02 20:14:32
Message-ID: 20100802201432.C5A4DAC7A9 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1158474 by pedrol:

Fix in MacOSX backend for initial MIDI program changes, muted MIDI channels, locked \
channels and MIDI reset messages.

 M  +2 -2      ChangeLog  
 M  +9 -0      mac/macmidiobject.cpp  
 M  +1 -0      mac/macmidiobject.h  
 M  +30 -10    mac/macmidioutput.cpp  
 M  +2 -1      mac/macmidioutput.h  


--- trunk/extragear/multimedia/kmid/ChangeLog #1158473:1158474
@@ -1,6 +1,6 @@
 2010-08-02 Pedro Lopez-Cabanillas
-    * Fix in ALSA sequencer backend for initial MIDI program changes with 
-      locked MIDI channels and MIDI reset messages.  
+    * Fixes in ALSA sequencer, Windows and Mac backends for initial MIDI program 
+      changes with locked MIDI channels and MIDI reset messages.  
     
 2010-08-01 Pedro Lopez-Cabanillas
     * DBus interfaces org.kde.KMid and org.kde.KMidPart offered by the main 
--- trunk/extragear/multimedia/kmid/mac/macmidiobject.cpp #1158473:1158474
@@ -385,6 +385,7 @@
             if (currentTime() == 0) {
                 d->m_output->sendResetMessage();
                 d->m_output->resetControllers();
+                sendInitialProgramChanges();
             }
             result = MusicPlayerStart ( d->m_player );
             if (result == noErr)
@@ -1066,6 +1067,14 @@
         return QVariant();
     }
 
+    void MacMIDIObject::sendInitialProgramChanges()
+    {
+        for (int i = 0; i < MIDI_CHANNELS; ++i) {
+            int patch(d->m_channelPatches[i]);
+            d->m_output->sendInitialProgram(i, patch);
 }
+    }
 
+}
+
 #include "macmidiobject.moc"
--- trunk/extragear/multimedia/kmid/mac/macmidiobject.h #1158473:1158474
@@ -98,6 +98,7 @@
         void createFeedbackTrack();
         void sendUserSignal(UserDataType userType,
                 MusicTimeStamp time);
+        void sendInitialProgramChanges();
 
     public Q_SLOTS:
         void setTickInterval(qint32 interval);
--- trunk/extragear/multimedia/kmid/mac/macmidioutput.cpp #1158473:1158474
@@ -44,6 +44,7 @@
                 m_volume[chan] = 100;
                 m_muted[chan] = false;
                 m_locked[chan] = false;
+                m_lockedpgm[chan] = 0;
             }
         }
 
@@ -96,9 +97,9 @@
 
         void transformProgramEvent(MIDIPacket *packet)
         {
-            if (m_mapper != NULL && m_mapper->isOK()) {
                 int channel = packet->data[0] & 0x0f;
                 m_lastpgm[channel] = packet->data[1];
+            if (m_mapper != NULL && m_mapper->isOK()) {
                 int pgm = m_mapper->patch(channel, m_lastpgm[channel]);
                 if (pgm >= 0 && pgm < 128)
                     packet->data[1] = pgm;
@@ -162,6 +163,7 @@
         int m_volume[MIDI_CHANNELS];
         bool m_muted[MIDI_CHANNELS];
         bool m_locked[MIDI_CHANNELS];
+        int m_lockedpgm[MIDI_CHANNELS];
         QByteArray m_resetMessage;
     };
 
@@ -205,7 +207,6 @@
 
     int MacMIDIOutput::outputDevice() const
     {
-
         return d->m_outputDevices.indexOf(d->m_currentOutput);
     }
 
@@ -364,6 +365,8 @@
         if (channel >= 0 && channel < MIDI_CHANNELS) {
             if (d->m_locked[channel] != lock) {
                 d->m_locked[channel] = lock;
+                if (lock)
+                    d->m_lockedpgm[channel] = d->m_lastpgm[channel];
                 emit lockedChanged( channel, lock );
             }
         }
@@ -566,7 +569,8 @@
             sendEvents(pktlist);
     }
 
-    void MacMIDIOutput::sendEvents(const MIDIPacketList* events)
+    void MacMIDIOutput::sendEvents( const MIDIPacketList* events,
+                                    bool discardable )
     {
         quint8 buf[4096];
         MIDIPacketList* pktlist = (MIDIPacketList*) &buf;
@@ -577,13 +581,13 @@
             d->transform(&dstpacket);
             quint8 status = dstpacket.data[0] & 0xf0;
             quint8 chan = dstpacket.data[0] & 0x0f;
-            bool ok = ( status >= MIDI_STATUS_NOTEOFF ) &&
-                      ( ( status == MIDI_STATUS_SYSEX ) |
-                        ( status < MIDI_STATUS_SYSEX &&
-                          !d->m_muted[chan] ) );
-            if ( ok && status == MIDI_STATUS_PROGRAMCHANGE )
-                ok = !d->m_locked[chan];
-            if (ok)
+            bool reject = ( status < MIDI_STATUS_NOTEOFF ) ||
+                          ( status >= MIDI_STATUS_SYSEX ) ||
+                          ((status < MIDI_STATUS_SYSEX) &&
+                            discardable && d->m_muted[chan]);
+            if ( discardable && status == MIDI_STATUS_PROGRAMCHANGE )
+                 reject |= d->m_locked[chan];
+            if (!reject)
                curpacket = MIDIPacketListAdd(pktlist, sizeof(buf), curpacket, 0,
                            dstpacket.length, (const Byte*)&dstpacket.data);
             srcpacket = MIDIPacketNext(srcpacket);
@@ -591,6 +595,22 @@
         MIDISend(d->m_outPort, d->m_destination, pktlist);
     }
 
+    void MacMIDIOutput::sendInitialProgram(int chan, int program)
+    {
+        int pgm(d->m_locked[chan] ? d->m_lockedpgm[chan] : program);
+        if (pgm > -1) {
+            quint8 data[2];
+            MIDIPacketList pktlist ;
+            MIDIPacket* packet = MIDIPacketListInit(&pktlist);
+            data[0] = MIDI_STATUS_PROGRAMCHANGE | (chan & 0x0f);
+            data[1] = pgm;
+            packet = MIDIPacketListAdd(&pktlist, sizeof(pktlist), packet, 0,
+                sizeof(data), data);
+            if (packet != NULL)
+                sendEvents(&pktlist, false);
 }
+    }
 
+}
+
 #include "macmidioutput.moc"
--- trunk/extragear/multimedia/kmid/mac/macmidioutput.h #1158473:1158474
@@ -57,7 +57,7 @@
         bool setOutputDevice(int);
         bool setOutputDeviceName(const QString &newOutputDevice);
         MIDIClientRef client() const;
-        void sendEvents(const MIDIPacketList* events);
+        void sendEvents(const MIDIPacketList* events, bool discardable = true);
 
     public Q_SLOTS:
         void setVolume(int channel, qreal);
@@ -80,6 +80,7 @@
         void sendChannelPressure(int chan, int value);
         void sendPitchBend(int chan, int value);
         void sendSysexEvent(const QByteArray& data);
+        void sendInitialProgram(int chan, int program);
 
     private:
         class MacMIDIOutputPrivate;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic