From ea7a3a8c300cf24cee50a834aa0f579fada5f660 Mon Sep 17 00:00:00 2001 From: Yuri Date: Tue, 15 Jan 2019 01:34:50 -0800 Subject: [PATCH] FreeBSD compatibility patch --- Makefile.am | 11 +++++++++++ configure.ac | 8 ++++++-- src/core/clock.cpp | 4 ++-- src/core/clock.h | 2 +- src/core/conf.cpp | 4 ++-- src/core/const.h | 4 ++++ src/core/init.cpp | 4 ++-- src/core/kernelAudio.cpp | 18 +++++++++++++----- src/core/kernelAudio.h | 6 +++--- src/core/mixer.cpp | 2 +- src/deps/rtaudio-mod/RtAudio.cpp | 2 +- src/deps/rtaudio-mod/RtAudio.h | 2 +- src/glue/main.cpp | 2 +- src/glue/transport.cpp | 4 ++-- src/gui/dialogs/pluginWindowGUI.cpp | 2 +- src/gui/elems/config/tabAudio.cpp | 28 ++++++++++++++++++++++++++++ src/gui/elems/config/tabMidi.cpp | 5 +++++ src/utils/fs.cpp | 8 ++++---- src/utils/gui.cpp | 4 ++-- src/utils/string.cpp | 2 +- 20 files changed, 91 insertions(+), 31 deletions(-) diff --git a/Makefile.am b/Makefile.am index 49adf3031..f23d2ed7c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -376,6 +376,17 @@ ldAdd += -lsndfile -lfltk -lXext -lX11 -lXft -lXpm -lm -ljack -lasound \ endif +if FREEBSD + +# Add preprocessor flags to enable ALSA, Pulse and JACK in RtAudio. +cppFlags += -D__LINUX_PULSE__ -D__UNIX_JACK__ + +ldAdd += -lsndfile -lfltk -lXext -lX11 -lXft -lXpm -lm -ljack -lasound \ + -lpthread -lpulse-simple -lpulse -lsamplerate -lrtmidi -ljansson \ + -lfreetype + +endif + if OSX sourcesExtra += src/utils/cocoa.mm src/utils/cocoa.h diff --git a/configure.ac b/configure.ac index 9f772f66a..fd9cdd62d 100644 --- a/configure.ac +++ b/configure.ac @@ -15,13 +15,16 @@ AM_INIT_AUTOMAKE([subdir-objects]) # Usage: ./configure --target=[windows | linux | osx] if test "$target" = ""; then - AC_MSG_ERROR(["target OS not specified. Please run ./configure --target="]) + AC_MSG_ERROR(["target OS not specified. Please run ./configure --target="]) fi case "$target" in linux) os=linux ;; + freebsd) + os=freebsd + ;; windows) os=windows ;; @@ -33,6 +36,7 @@ case "$target" in ;; esac AM_CONDITIONAL(LINUX, test "x$os" = "xlinux") +AM_CONDITIONAL(FREEBSD, test "x$os" = "xfreebsd") AM_CONDITIONAL(WINDOWS, test "x$os" = "xwindows") AM_CONDITIONAL(OSX, test "x$os" = "xosx") @@ -186,7 +190,7 @@ AC_LANG_POP # Check for linux header files. -if test "x$os" = "xlinux"; then +if test "x$os" = "xlinux" || test "x$os" = "xfreebsd"; then AC_LANG_PUSH([C++]) AC_CHECK_HEADER( diff --git a/src/core/clock.cpp b/src/core/clock.cpp index 1fe8eac75..d478f640d 100644 --- a/src/core/clock.cpp +++ b/src/core/clock.cpp @@ -61,7 +61,7 @@ int midiTCseconds = 0; int midiTCminutes = 0; int midiTChours = 0; -#ifdef G_OS_LINUX +#if defined(G_OS_LINUX) || defined(G_OS_FREEBSD) kernelAudio::JackState jackStatePrev; #endif @@ -328,7 +328,7 @@ void sendMIDIrewind() /* -------------------------------------------------------------------------- */ -#ifdef G_OS_LINUX +#if defined(G_OS_LINUX) || defined(G_OS_FREEBSD) void recvJackSync() { diff --git a/src/core/clock.h b/src/core/clock.h index 6d0eac099..3978f2511 100644 --- a/src/core/clock.h +++ b/src/core/clock.h @@ -45,7 +45,7 @@ Rewinds timecode to beat 0 and also send a MTC full frame to cue the slave. */ void sendMIDIrewind(); -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) void recvJackSync(); #endif diff --git a/src/core/conf.cpp b/src/core/conf.cpp index bfb02f575..81ea910cd 100644 --- a/src/core/conf.cpp +++ b/src/core/conf.cpp @@ -116,7 +116,7 @@ to OS. */ int createConfigFolder() { -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) if (gu_dirExists(confDirPath)) return 1; @@ -266,7 +266,7 @@ void init() /* Initialize confFilePath, i.e. the configuration file. In windows it is in * the same dir of the .exe, while in Linux and OS X in ~/.giada */ -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) confFilePath = gu_getHomePath() + G_SLASH + CONF_FILENAME; confDirPath = gu_getHomePath() + G_SLASH; diff --git a/src/core/const.h b/src/core/const.h index a00f6d656..35760a236 100644 --- a/src/core/const.h +++ b/src/core/const.h @@ -36,6 +36,8 @@ #define G_OS_MAC #elif defined(__linux__) #define G_OS_LINUX +#elif defined(__FreeBSD__) + #define G_OS_FREEBSD #endif #ifndef BUILD_DATE @@ -138,6 +140,8 @@ constexpr int G_MAX_POLYPHONY = 32; /* -- default system -------------------------------------------------------- */ #if defined(G_OS_LINUX) #define G_DEFAULT_SOUNDSYS G_SYS_API_NONE +#elif defined(G_OS_FREEBSD) + #define G_DEFAULT_SOUNDSYS G_SYS_API_PULSE #elif defined(G_OS_WINDOWS) #define G_DEFAULT_SOUNDSYS G_SYS_API_DS #elif defined(G_OS_MAC) diff --git a/src/core/init.cpp b/src/core/init.cpp index ef5515924..4d23b93b4 100644 --- a/src/core/init.cpp +++ b/src/core/init.cpp @@ -30,7 +30,7 @@ #ifdef __APPLE__ #include #endif -#if defined(__linux__) && defined(WITH_VST) +#if (defined(__linux__) || defined(__FreeBSD__)) && defined(WITH_VST) #include // For XInitThreads #endif #include @@ -153,7 +153,7 @@ void initGUI_(int argc, char** argv) plug-ins go nuts and crash hard. It seems that some plug-ins or our Juce-based PluginHost use Xlib concurrently. */ -#if defined(__linux__) && defined(WITH_VST) +#if (defined(__linux__) || defined(__FreeBSD__)) && defined(WITH_VST) XInitThreads(); #endif diff --git a/src/core/kernelAudio.cpp b/src/core/kernelAudio.cpp index 4d42806b8..8cf7ac738 100644 --- a/src/core/kernelAudio.cpp +++ b/src/core/kernelAudio.cpp @@ -53,7 +53,7 @@ bool inputEnabled = false; unsigned realBufsize = 0; // reale bufsize from the soundcard int api = 0; -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) JackState jackState; @@ -96,6 +96,14 @@ int openDevice() if (api == G_SYS_API_PULSE && hasAPI(RtAudio::LINUX_PULSE)) rtSystem = new RtAudio(RtAudio::LINUX_PULSE); +#elif defined(__FreeBSD__) + + if (api == G_SYS_API_JACK && hasAPI(RtAudio::UNIX_JACK)) + rtSystem = new RtAudio(RtAudio::UNIX_JACK); + else + if (api == G_SYS_API_PULSE && hasAPI(RtAudio::LINUX_PULSE)) + rtSystem = new RtAudio(RtAudio::LINUX_PULSE); + #elif defined(_WIN32) if (api == G_SYS_API_DS && hasAPI(RtAudio::WINDOWS_DS)) @@ -159,7 +167,7 @@ int openDevice() realBufsize = conf::buffersize; -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) if (api == G_SYS_API_JACK) { conf::samplerate = getFreq(conf::soundDeviceOut, 0); @@ -243,7 +251,7 @@ string getDeviceName(unsigned dev) int closeDevice() { if (rtSystem->isStreamOpen()) { -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) rtSystem->abortStream(); // stopStream seems to lock the thread #elif defined(_WIN32) rtSystem->stopStream(); // on Windows it's the opposite @@ -445,7 +453,7 @@ int getAPI() { return api; } /* -------------------------------------------------------------------------- */ -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) const JackState &jackTransportQuery() @@ -512,6 +520,6 @@ void jackStop() jack_transport_stop(jackGetHandle()); } -#endif // #ifdef __linux__ +#endif // defined(__linux__) || defined(__FreeBSD__) }}}; // giada::m::kernelAudio diff --git a/src/core/kernelAudio.h b/src/core/kernelAudio.h index 7177923cf..dcbe4935a 100644 --- a/src/core/kernelAudio.h +++ b/src/core/kernelAudio.h @@ -30,7 +30,7 @@ #include -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) #include #include #include @@ -45,7 +45,7 @@ namespace giada { namespace m { namespace kernelAudio { -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) struct JackState { @@ -80,7 +80,7 @@ int getDefaultIn(); bool hasAPI(int API); int getAPI(); -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) void jackStart(); void jackStop(); diff --git a/src/core/mixer.cpp b/src/core/mixer.cpp index 120c76dcb..ccf132db4 100644 --- a/src/core/mixer.cpp +++ b/src/core/mixer.cpp @@ -324,7 +324,7 @@ int masterPlay(void* outBuf, void* inBuf, unsigned bufferSize, if (!ready) return 0; -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) clock::recvJackSync(); #endif diff --git a/src/deps/rtaudio-mod/RtAudio.cpp b/src/deps/rtaudio-mod/RtAudio.cpp index 1586aaaf1..4d732723c 100755 --- a/src/deps/rtaudio-mod/RtAudio.cpp +++ b/src/deps/rtaudio-mod/RtAudio.cpp @@ -1941,7 +1941,7 @@ struct JackHandle { }; /* --- Monocasual hack ------------------------------------------------------ */ -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) void *RtApi :: __HACK__getJackClient() { JackHandle *handle = (JackHandle *) stream_.apiHandle; return (void*) handle->client; diff --git a/src/deps/rtaudio-mod/RtAudio.h b/src/deps/rtaudio-mod/RtAudio.h index ddb42ccb7..5e95b236b 100755 --- a/src/deps/rtaudio-mod/RtAudio.h +++ b/src/deps/rtaudio-mod/RtAudio.h @@ -676,7 +676,7 @@ class RtApi public: /* --- Monocasual hack ---------------------------------------------------- */ - #ifdef __linux__ + #if defined(__linux__) || defined(__FreeBSD__) void *__HACK__getJackClient(); #endif /* ------------------------------------------------------------------------ */ diff --git a/src/glue/main.cpp b/src/glue/main.cpp index 3e637e51a..40b23463f 100644 --- a/src/glue/main.cpp +++ b/src/glue/main.cpp @@ -107,7 +107,7 @@ void setBpm(const char* v1, const char* v2) float f = atof(v1) + (atof(v2)/10); string s = string(v1) + "." + string(v2); -#ifdef G_OS_LINUX +#if defined(G_OS_LINUX) || defined(G_OS_FREEBSD) if (kernelAudio::getAPI() == G_SYS_API_JACK) kernelAudio::jackSetBpm(f); else diff --git a/src/glue/transport.cpp b/src/glue/transport.cpp index 51c370fcf..6e28ccf41 100644 --- a/src/glue/transport.cpp +++ b/src/glue/transport.cpp @@ -62,7 +62,7 @@ void startSeq(bool gui) { clock::start(); -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) kernelAudio::jackStart(); #endif @@ -81,7 +81,7 @@ void stopSeq(bool gui) { mh::stopSequencer(); -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) kernelAudio::jackStop(); #endif diff --git a/src/gui/dialogs/pluginWindowGUI.cpp b/src/gui/dialogs/pluginWindowGUI.cpp index 6eb8181a6..e1a21608f 100644 --- a/src/gui/dialogs/pluginWindowGUI.cpp +++ b/src/gui/dialogs/pluginWindowGUI.cpp @@ -53,7 +53,7 @@ gdPluginWindowGUI::gdPluginWindowGUI(Plugin* plugin) { show(); -#if defined(G_OS_LINUX) || defined(G_OS_MAC) +#if defined(G_OS_LINUX) || defined(G_OS_MAC) || defined(G_OS_FREEBSD) /* Fl_Window::show() is not guaranteed to show and draw the window on all platforms immediately. Instead this is done in the background; particularly on diff --git a/src/gui/elems/config/tabAudio.cpp b/src/gui/elems/config/tabAudio.cpp index 803f1b85a..a6bcbd2d2 100644 --- a/src/gui/elems/config/tabAudio.cpp +++ b/src/gui/elems/config/tabAudio.cpp @@ -96,6 +96,27 @@ geTabAudio::geTabAudio(int X, int Y, int W, int H) break; } +#elif defined(__FreeBSD__) + + if (kernelAudio::hasAPI(RtAudio::UNIX_JACK)) + soundsys->add("Jack"); + if (kernelAudio::hasAPI(RtAudio::LINUX_PULSE)) + soundsys->add("PulseAudio"); + + switch (conf::soundSystem) { + case G_SYS_API_NONE: + soundsys->showItem("(none)"); + break; + case G_SYS_API_JACK: + soundsys->showItem("Jack"); + buffersize->deactivate(); + samplerate->deactivate(); + break; + case G_SYS_API_PULSE: + soundsys->showItem("PulseAudio"); + break; + } + #elif defined(_WIN32) if (kernelAudio::hasAPI(RtAudio::WINDOWS_DS)) @@ -467,6 +488,13 @@ void geTabAudio::save() else if (text == "PulseAudio") conf::soundSystem = G_SYS_API_PULSE; +#elif defined(__FreeBSD__) + + else if (text == "Jack") + conf::soundSystem = G_SYS_API_JACK; + else if (text == "PulseAudio") + conf::soundSystem = G_SYS_API_PULSE; + #elif defined(_WIN32) else if (text == "DirectSound") diff --git a/src/gui/elems/config/tabMidi.cpp b/src/gui/elems/config/tabMidi.cpp index 205458e4e..9f8e8fa1d 100644 --- a/src/gui/elems/config/tabMidi.cpp +++ b/src/gui/elems/config/tabMidi.cpp @@ -192,6 +192,11 @@ void geTabMidi::fetchSystems() if (kernelMidi::hasAPI(RtMidi::UNIX_JACK)) system->add("Jack"); +#elif defined(__FreeBSD__) + + if (kernelMidi::hasAPI(RtMidi::UNIX_JACK)) + system->add("Jack"); + #elif defined(_WIN32) if (kernelMidi::hasAPI(RtMidi::WINDOWS_MM)) diff --git a/src/utils/fs.cpp b/src/utils/fs.cpp index d3c83089d..976545bd0 100644 --- a/src/utils/fs.cpp +++ b/src/utils/fs.cpp @@ -81,7 +81,7 @@ bool gu_isDir(const string &path) { bool ret; -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) struct stat s1; stat(path.c_str(), &s1); @@ -134,7 +134,7 @@ bool gu_dirExists(const string &path) bool gu_mkdir(const string &path) { -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) if (mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0) #else if (_mkdir(path.c_str()) == 0) @@ -246,7 +246,7 @@ string gu_getHomePath() { char path[PATH_MAX]; -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) snprintf(path, PATH_MAX, "%s/.giada", getenv("HOME")); @@ -306,4 +306,4 @@ std::string gu_getUpDir(const std::string& s) #endif return s.substr(0, s.find_last_of(G_SLASH_STR)) + G_SLASH_STR; -} \ No newline at end of file +} diff --git a/src/utils/gui.cpp b/src/utils/gui.cpp index 6c1b4167a..c3338abcb 100644 --- a/src/utils/gui.cpp +++ b/src/utils/gui.cpp @@ -30,7 +30,7 @@ #include #if defined(_WIN32) #include "../ext/resource.h" -#elif defined(__linux__) +#elif defined(__linux__) || defined(__FreeBSD__) #include #endif #include "../core/mixer.h" @@ -146,7 +146,7 @@ void gu_updateMainWinLabel(const string& s) void gu_setFavicon(Fl_Window* w) { -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) fl_open_display(); Pixmap p, mask; diff --git a/src/utils/string.cpp b/src/utils/string.cpp index 2438f395d..bfa6f7dd9 100644 --- a/src/utils/string.cpp +++ b/src/utils/string.cpp @@ -42,7 +42,7 @@ std::string getRealPath(const std::string& path) { std::string out = ""; -#if defined(G_OS_LINUX) || defined(G_OS_MAC) +#if defined(G_OS_LINUX) || defined(G_OS_FREEBSD) || defined(G_OS_MAC) char *buf = realpath(path.c_str(), nullptr);