Skip to content

Commit

Permalink
LMMS#1153: added basic apple midi support
Browse files Browse the repository at this point in the history
  • Loading branch information
mauicoder committed Aug 9, 2015
1 parent 2294614 commit 275bcb5
Show file tree
Hide file tree
Showing 7 changed files with 828 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ IF(LMMS_BUILD_APPLE)
SET(WANT_VST OFF)
SET(STATUS_ALSA "<not supported on this platform>")
SET(STATUS_PULSEAUDIO "<not supported on this platform>")
SET(STATUS_APPLEMIDI "OK")
# MacPorts: /opt/local/lib
LINK_DIRECTORIES(${LINK_DIRECTORIES} /opt/local/lib)
ENDIF(LMMS_BUILD_APPLE)
Expand All @@ -69,6 +70,7 @@ IF(LMMS_BUILD_WIN32)
SET(STATUS_JACK "<not supported on this platform>")
SET(STATUS_PULSEAUDIO "<not supported on this platform>")
SET(STATUS_WINMM "OK")
SET(STATUS_APPLEMIDI "<not supported on this platform>")
ELSE(LMMS_BUILD_WIN32)
SET(STATUS_WINMM "<not supported on this platform>")
ENDIF(LMMS_BUILD_WIN32)
Expand Down Expand Up @@ -531,6 +533,7 @@ MESSAGE(
"* ALSA : ${STATUS_ALSA}\n"
"* OSS : ${STATUS_OSS}\n"
"* WinMM : ${STATUS_WINMM}\n"
"* AppleMidi : ${STATUS_APPLEMIDI}\n"
)

MESSAGE(
Expand Down
158 changes: 158 additions & 0 deletions include/MidiApple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* MidiApple.h - Apple raw MIDI client
*
* Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2015 Maurizio Lo Bosco (rageboge on github)
*
* This file is part of LMMS - http://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#ifndef MIDI_APPLE_H
#define MIDI_APPLE_H

#include "lmmsconfig.h"

#ifdef LMMS_BUILD_APPLE

#include "MidiClient.h"
#include "MidiPort.h"
#include <CoreMIDI/CoreMIDI.h>


class QLineEdit;


class MidiApple : public QObject, public MidiClient
{
Q_OBJECT
public:
MidiApple();
virtual ~MidiApple();

static QString probeDevice();


inline static QString name()
{
return QT_TRANSLATE_NOOP( "setupWidget", "Apple MIDI" );
}

virtual void processOutEvent( const MidiEvent & _me,
const MidiTime & _time,
const MidiPort * _port );

virtual void applyPortMode( MidiPort * _port );
virtual void removePort( MidiPort * _port );


// list devices as ports
virtual QStringList readablePorts() const
{
return m_inputDevices.keys();
}

virtual QStringList writablePorts() const
{
return m_outputDevices.keys();
}

// return name of port which specified MIDI event came from
virtual QString sourcePortName( const MidiEvent & ) const;

// (un)subscribe given MidiPort to/from destination-port
virtual void subscribeReadablePort( MidiPort * _port,
const QString & _dest,
bool _subscribe = true );

virtual void subscribeWritablePort( MidiPort * _port,
const QString & _dest,
bool _subscribe = true );

virtual void connectRPChanged( QObject * _receiver,
const char * _member )
{
connect( this, SIGNAL( readablePortsChanged() ),
_receiver, _member );
}


virtual void connectWPChanged( QObject * _receiver,
const char * _member )
{
connect( this, SIGNAL( writablePortsChanged() ),
_receiver, _member );
}


virtual bool isRaw() const
{
return false;
}


class setupWidget : public MidiClient::setupWidget
{
public:
setupWidget( QWidget * _parent );
virtual ~setupWidget();

void saveSettings()
{
}
} ;


private:// slots:
void updateDeviceList();


private:
void openDevices();
void closeDevices();
void openMidiReference( MIDIEndpointRef reference, QString refName,bool isIn );
MIDIClientRef getMidiClientRef();
void midiInClose( MIDIEndpointRef reference );
static void NotifyCallback( const MIDINotification *message, void *refCon );
static void ReadCallback( const MIDIPacketList *pktlist, void *readProcRefCon, void *srcConnRefCon );
void HandleReadCallback( const MIDIPacketList *pktlist, void *srcConnRefCon );
void notifyMidiPortList( MidiPortList portList, MidiEvent midiEvent);
char * getFullName( MIDIEndpointRef &endpoint_ref );
void sendMidiOut( MIDIEndpointRef & endPointRef, const MidiEvent& event );
MIDIPacketList createMidiPacketList( const MidiEvent& event );

MIDIClientRef mClient = 0;
QMap<QString, MIDIEndpointRef> m_inputDevices;
QMap<QString, MIDIEndpointRef> m_outputDevices;
QMap<MIDIEndpointRef, MIDIPortRef> m_sourcePortRef;

// subscriptions
typedef QMap<QString, MidiPortList> SubMap;
SubMap m_inputSubs;
SubMap m_outputSubs;

signals:
void readablePortsChanged();
void writablePortsChanged();

} ;

#endif


#endif
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ IF(LMMS_BUILD_WIN32)
SET(EXTRA_LIBRARIES "-lwinmm")
ENDIF()

IF(LMMS_BUILD_APPLE)
SET(EXTRA_LIBRARIES "-framework CoreMIDI")
ENDIF()

SET(LMMS_REQUIRED_LIBS
${CMAKE_THREAD_LIBS_INIT}
${QT_LIBRARIES}
Expand Down
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ set(LMMS_SRCS
core/midi/MidiClient.cpp
core/midi/MidiController.cpp
core/midi/MidiOss.cpp
core/midi/MidiApple.cpp
core/midi/MidiPort.cpp
core/midi/MidiTime.cpp
core/midi/MidiWinMM.cpp
Expand Down
13 changes: 13 additions & 0 deletions src/core/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "MidiAlsaSeq.h"
#include "MidiOss.h"
#include "MidiWinMM.h"
#include "MidiApple.h"
#include "MidiDummy.h"

#include "MemoryHelper.h"
Expand Down Expand Up @@ -894,6 +895,18 @@ MidiClient * Mixer::tryMidiClients()
}
#endif

#ifdef LMMS_BUILD_APPLE
printf( "trying midi apple...\n" );
if( client_name == MidiApple::name() || client_name == "" )
{
MidiApple * mapple = new MidiApple;
m_midiClientName = MidiApple::name();
printf( "Returning midi apple\n" );
return mapple;
}
printf( "midi apple didn't work: client_name=%s\n", client_name.toUtf8().constData());
#endif

printf( "Couldn't create MIDI-client, neither with ALSA nor with "
"OSS. Will use dummy-MIDI-client.\n" );

Expand Down
Loading

0 comments on commit 275bcb5

Please sign in to comment.