Skip to content

Commit

Permalink
Option to enable PortMidi on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
shoogle committed Aug 8, 2016
1 parent d39279b commit 8c74814
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 76 deletions.
26 changes: 17 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ endif (APPLE)
# Disable components not supported on Linux/BSD
if (NOT APPLE AND NOT MINGW)
set(NIX_NOT_AVAIL "Not available on Linux/BSD")
option(BUILD_PORTMIDI "PortMidi disabled on Linux. (It uses ALSA but it's better to use ALSA directly)" OFF)
endif (NOT APPLE AND NOT MINGW)

option(AEOLUS "Enable pipe organ synthesizer" OFF)
Expand All @@ -101,6 +102,7 @@ option(BUILD_JACK "Build with support for ${JACK_LONGNAME} audio backend. JAC
option(BUILD_PULSEAUDIO "Build with support for PulseAudio audio backend." ON)
option(BUILD_ALSA "Build with support for ALSA audio backend." ON)
option(BUILD_PORTAUDIO "Build with support for PortAudio audio backend." ON)
option(BUILD_PORTMIDI "Build with support for PortAudio's MIDI features." ${BUILD_PORTAUDIO}) # PortAudio required
option(BUILD_PCH "Build using precompiled headers." OFF)

if (APPLE)
Expand Down Expand Up @@ -312,25 +314,31 @@ ENDIF(BUILD_JACK)
if (BUILD_PORTAUDIO)
if (MINGW)
set ( USE_PORTAUDIO 1 )
set ( USE_PORTMIDI 1 )
else (MINGW)
PKGCONFIG1 (portaudio-2.0 19 PORTAUDIO_INCDIR PORTAUDIO_LIBDIR PORTAUDIO_LIB PORTAUDIO_CPP)
if (PORTAUDIO_INCDIR)
message(STATUS "PortAudio found. PortAudio support enabled. INCDIR ${PORTAUDIO_INCDIR}, LIBDIR ${PORTAUDIO_LIBDIR}, LIB ${PORTAUDIO_LIB}")
message("PortAudio found. PortAudio support enabled. INCDIR ${PORTAUDIO_INCDIR}, LIBDIR ${PORTAUDIO_LIBDIR}, LIB ${PORTAUDIO_LIB}")
set ( USE_PORTAUDIO 1 )
else (PORTAUDIO_INCDIR)
message(SEND_ERROR "Error: PortAudio support requested (BUILD_PORTAUDIO=${BUILD_PORTAUDIO}), but portaudio-2.0 version 19 was not found (package portaudio19-dev)")
endif (PORTAUDIO_INCDIR)
if (APPLE)
set (USE_PORTMIDI 1)
else (APPLE)
set (USE_PORTMIDI 0)
endif (APPLE)
endif (MINGW)
else (BUILD_PORTAUDIO)
message(STATUS "PortAudio support disabled")
endif (BUILD_PORTAUDIO)

##
## PortMidi
##

if (BUILD_PORTMIDI)
if (NOT BUILD_PORTAUDIO)
message(SEND_ERROR "Error: PortMidi support requested (BUILD_PORTMIDI=${BUILD_PORTMIDI}), but PortAudio support is disabled (BUILD_PORTAUDIO=${BUILD_PORTAUDIO}). PortMidi requires PortAudio.")
endif (NOT BUILD_PORTAUDIO)
set (USE_PORTMIDI 1)
else (BUILD_PORTMIDI)
message(STATUS "PortMidi support disabled")
endif (BUILD_PORTMIDI)

if (APPLE)
if(SOUNDFONT3)
Expand Down Expand Up @@ -543,9 +551,9 @@ add_subdirectory(fonttools EXCLUDE_FROM_ALL)
add_subdirectory(manual)
add_subdirectory(demos)

if (USE_PORTMIDI)
if (USE_PORTMIDI AND (MINGW OR APPLE))
subdirs (thirdparty/portmidi)
endif (USE_PORTMIDI)
endif (USE_PORTMIDI AND (MINGW OR APPLE))

if (AEOLUS)
subdirs (aeolus)
Expand Down
18 changes: 14 additions & 4 deletions mscore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ if (MINGW)
set (resource_file ${PROJECT_BINARY_DIR}/resfile.o)
else (MINGW)
if (USE_ALSA)
set (AUDIO ${AUDIO} alsa.cpp mididriver.cpp)
set (AUDIO ${AUDIO} alsa.cpp)
endif (USE_ALSA)
endif (MINGW)

Expand All @@ -174,6 +174,10 @@ if (USE_JACK)
set (AUDIO ${AUDIO} jackaudio.cpp jackweakapi.cpp)
endif (USE_JACK)

if (USE_ALSA OR USE_PORTMIDI)
set (AUDIO ${AUDIO} mididriver.cpp)
endif (USE_ALSA OR USE_PORTMIDI)

if (${CMAKE_SYSTEM} MATCHES "GNU-0.3")
# Include some cmake support file
INCLUDE (Platform/GNU)
Expand Down Expand Up @@ -484,6 +488,15 @@ else (MINGW)
target_link_libraries(mscore ${PORTAUDIO_LIB})
endif (USE_PORTAUDIO)

if (USE_PORTMIDI)
if (APPLE)
set(PORTMIDI_LIB portmidi)
else (APPLE)
set(PORTMIDI_LIB -lportmidi -lporttime) # Remove -lporttime on RPM-based systems where PortTime is part of PortMidi.
endif (APPLE)
target_link_libraries(mscore ${PORTMIDI_LIB})
endif (USE_PORTMIDI)

if (USE_PULSEAUDIO)
target_link_libraries(mscore ${PULSEAUDIO_LIBRARY})
endif (USE_PULSEAUDIO)
Expand All @@ -502,9 +515,6 @@ else (MINGW)
endif (OMR)

if (APPLE)
if (USE_PORTMIDI)
target_link_libraries(mscore portmidi)
endif (USE_PORTMIDI)
target_link_libraries(mscore ${OsxFrameworks})
else (APPLE)
target_link_libraries(mscore rt)
Expand Down
3 changes: 3 additions & 0 deletions mscore/pa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@

#include <portaudio.h>
#include "mididriver.h"

#ifdef USE_PORTMIDI
#include "pm.h"
#endif

namespace Ms {

Expand Down
68 changes: 6 additions & 62 deletions mscore/pm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
#include <mmsystem.h>
#endif

#include "portmidi/porttime/porttime.h"
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
#include "portmidi/porttime/porttime.h"
#else
#include <porttime.h>
#endif

#include "preferences.h"
#include "pm.h"
Expand All @@ -32,66 +36,6 @@

namespace Ms {

//---------------------------------------------------------
// Port
//---------------------------------------------------------

Port::Port()
{
type = ZERO_TYPE;
}

Port::Port(unsigned char client, unsigned char port)
{
_alsaPort = port;
_alsaClient = client;
type = ALSA_TYPE;
}

//---------------------------------------------------------
// setZero
//---------------------------------------------------------

void Port::setZero()
{
type = ZERO_TYPE;
}

//---------------------------------------------------------
// isZero
//---------------------------------------------------------

bool Port::isZero() const
{
return type == ZERO_TYPE;
}

//---------------------------------------------------------
// operator==
//---------------------------------------------------------

bool Port::operator==(const Port& p) const
{
if (type == ALSA_TYPE)
return _alsaPort == p._alsaPort && _alsaClient == p._alsaClient;
else
return true;
}

//---------------------------------------------------------
// operator<
//---------------------------------------------------------

bool Port::operator<(const Port& p) const
{
if (type == ALSA_TYPE) {
if (_alsaPort != p._alsaPort)
return _alsaPort < p._alsaPort;
return _alsaClient < p._alsaClient;
}
return false;
}

//---------------------------------------------------------
// PortMidiDriver
//---------------------------------------------------------
Expand Down Expand Up @@ -135,7 +79,7 @@ bool PortMidiDriver::init()
PmError error = Pm_OpenInput(&inputStream,
inputId,
(void*)DRIVER_INFO, INPUT_BUFFER_SIZE,
((long (*)(void*)) Pt_Time),
((PmTimeProcPtr) Pt_Time),
(void*)TIME_INFO);
if (error != pmNoError) {
const char* p = Pm_GetErrorText(error);
Expand Down
6 changes: 5 additions & 1 deletion mscore/pm.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
#include "config.h"
#include "mididriver.h"

#include "portmidi/pm_common/portmidi.h"
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
#include "portmidi/pm_common/portmidi.h"
#else
#include <portmidi.h>
#endif

namespace Ms {

Expand Down
4 changes: 4 additions & 0 deletions mscore/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
#include "scoreview.h"
#include "libmscore/sym.h"
#include "pa.h"

#ifdef USE_PORTMIDI
#include "pm.h"
#endif

#include "libmscore/page.h"
#include "file.h"
#include "libmscore/mscore.h"
Expand Down

0 comments on commit 8c74814

Please sign in to comment.