3acc363498
This commit contains changes required for MuseScore to compile under MSVC with no errors. There are several general categories of problems that resulted in errors with the compilation. Main issues: - Variable Length Arrays (VLA). This is a non-standard extension to C++, supported by clang toolchains, but not by MSVC. The initial workaround is to use std::vector<> instead of VLAs, eventually (if needed) with the original variable pointing to the beginning of the allocated array. More efficient alternatives are possible if profiling shows any code using VLAs to be timing-critical. - Floating-point constants not suffixed with "f" are doubles by default; in some instances, this leads to narrowing conversion errors (in other instances, just warnings). - MSVC does not support "or"/"and"/"not" in lieu of "||"/"&&"/"!". Changed unconditionally to use standard C++ symbols. - MSVC does not support the "__builtin_unreachable()" compiler hint. A similar, albeit not exactly equal, alternative is "__assume(0)", which is MSVC-specific. - MSVC does not support ranges in case statements. Replaced with list of cases instead of range (non-conditionally) Detailed changes, with per-file comments: - all.h: opt-in to deprecated features, include <io.h> and <process.h> instead of POSIX <unistd.h>, undefine "STRING_NONE" and "small", which Microsoft defines as macros, which result in compilation errors. - effects/compressor/zita.cpp: eliminated narrowing conversion error by appending "f" to float constants. - fluid/voice.cpp: appended "f" to float constants to eliminate narrowing conversion errors/warnings - libmscore/beam.cpp: conditionally replaced VLA - libmscore/edit.cpp: conditionally replaced VLA - libmscore/element.cpp: appended "f" to float constant - libmscore/fret.cpp: changed or -> || - libmscore/layout.cpp: conditionally replaced VLA - libmscore/mscore.cpp: conditionally replaced "__builtin_unreachable()" with "__assume(0)" for MSVC - libmscore/scorefile.coo: use correct char representation conversion for MSVC - libmscore/stringdata.cpp: conditionally replaced VLA - libmscore/system.cpp: conditionally replaced VLA - libmscroe/text.cpp: replaced range in case statement. - manual/genManual.cpp: use getopt() replacement. - midi/midifile.cpp: conditionally replaced VLA. This does not use the default replacement. - mscore/bb.cpp: replaced range in case statement. - mscore/capella.cpp: conditionally replaced VLA. Changed and -> && - mscore/driver:cpp: preclude errors due to macro redefinitions. - mscore/editstyle.cpp: conditionally replaced "__builtin_unreachable()" with "__assume(0)" for MSVC - mscore/importgtp-gp6.cpp: conditionally replaced VLA. - mscore/instrwidget.cpp: conditionally replaced VLA. - mscore/jackaudio.cpp: conditionally replaced VLA. Preclude errors due to macro redefinitions. - mscore/jackweakapi.cpp: Preclude errors due to macro redefinitions. Replacement for __atribute__((constructor)) through static object construction for MSVC. Force use of LoadLibraryA instead of LoadLibrary. - mscore/mididriver.h: Changed not -> ! - mscore/musescore.cpp: Changed not -> !. Conditionally replaced VLA. - mscore/resourceManager.cpp: conditionally replaced VLA. - mscore/timeline.cpp: conditionally replaced VLA. - omr/omrpage.cpp: conditionally replaced VLA. - synthesizer/msynthesizer.cpp: replaced UNIX sleep(1) method with MSVC Sleep(1000) (equivalent, but in ms instead of seconds) - synthesizer/msynthsizer.h: appended "f" to float constant - thirdparty/poppler/config.h: set defines for MSVC to preclude the use of inexistent libraries. - thirdparty/poppler/poppler/poppler-config.h: set defines for MSVC to preclude the use of inexistent libraries. Eliminated #defines for fmin and fmax which where causing problems. - thirdparty/poppler/poppler/PSOutputDev.cc: added #include <algorithm> for std::min() and std::max(). Note this is required per-C++ standard. - thirdparty/portmidi/pm_win/pmwinmm.c: undefined UNICODE to use char-based library functions. - thirdparty/qzip/qzip.cpp: changed or -> || - thirdparty/rtf2html/rtf_keyword.h: file format changed from Apple to UNIX, as MSVC does not supported the former. (NOT error related, just improvement on previous commit; manual/getopt/README.md: added link to source article)
147 lines
4.3 KiB
C++
147 lines
4.3 KiB
C++
//=============================================================================
|
|
// MuseScore
|
|
// Music Composition & Notation
|
|
//
|
|
// Copyright (C) 2002-2012 Werner Schweer
|
|
//
|
|
// This program is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License version 2
|
|
// as published by the Free Software Foundation and appearing in
|
|
// the file LICENCE.GPL
|
|
//=============================================================================
|
|
|
|
#if (defined (_MSCVER) || defined (_MSC_VER))
|
|
// Include stdint.h and #define _STDINT_H to prevent <systemdeps.h> from redefining types
|
|
// #undef UNICODE to force LoadLibrary to use the char-based implementation instead of the wchar_t one.
|
|
#include <stdint.h>
|
|
#define _STDINT_H 1
|
|
#endif
|
|
|
|
#include "config.h"
|
|
#include "preferences.h"
|
|
#include "driver.h"
|
|
|
|
#ifdef USE_JACK
|
|
#include "jackaudio.h"
|
|
#endif
|
|
|
|
|
|
#ifdef USE_ALSA
|
|
#include "alsa.h"
|
|
#endif
|
|
#ifdef USE_PORTAUDIO
|
|
#include "pa.h"
|
|
#endif
|
|
|
|
namespace Ms {
|
|
|
|
#ifdef USE_PULSEAUDIO
|
|
extern Driver* getPulseAudioDriver(Seq*);
|
|
#endif
|
|
|
|
bool alsaIsUsed = false, jackIsUsed = false, portAudioIsUsed = false, pulseAudioIsUsed = false;
|
|
|
|
|
|
//---------------------------------------------------------
|
|
// driverFactory
|
|
// driver can be: jack alsa pulse portaudio
|
|
//---------------------------------------------------------
|
|
|
|
Driver* driverFactory(Seq* seq, QString driverName)
|
|
{
|
|
Driver* driver = 0;
|
|
#if 1 // DEBUG: force "no audio"
|
|
bool useJackFlag = (preferences.getBool(PREF_IO_JACK_USEJACKAUDIO) || preferences.getBool(PREF_IO_JACK_USEJACKMIDI));
|
|
bool useAlsaFlag = preferences.getBool(PREF_IO_ALSA_USEALSAAUDIO);
|
|
bool usePortaudioFlag = preferences.getBool(PREF_IO_PORTAUDIO_USEPORTAUDIO);
|
|
bool usePulseAudioFlag = preferences.getBool(PREF_IO_PULSEAUDIO_USEPULSEAUDIO);
|
|
|
|
if (!driverName.isEmpty()) {
|
|
driverName = driverName.toLower();
|
|
useJackFlag = false;
|
|
useAlsaFlag = false;
|
|
usePortaudioFlag = false;
|
|
usePulseAudioFlag = false;
|
|
if (driverName == "jack")
|
|
useJackFlag = true;
|
|
else if (driverName == "alsa")
|
|
useAlsaFlag = true;
|
|
else if (driverName == "pulse")
|
|
usePulseAudioFlag = true;
|
|
else if (driverName == "portaudio")
|
|
usePortaudioFlag = true;
|
|
}
|
|
|
|
alsaIsUsed = false;
|
|
jackIsUsed = false;
|
|
portAudioIsUsed = false;
|
|
pulseAudioIsUsed = false;
|
|
|
|
#ifdef USE_PULSEAUDIO
|
|
if (usePulseAudioFlag) {
|
|
driver = getPulseAudioDriver(seq);
|
|
if (!driver->init()) {
|
|
qDebug("init PulseAudio failed");
|
|
delete driver;
|
|
driver = 0;
|
|
}
|
|
else
|
|
pulseAudioIsUsed = true;
|
|
}
|
|
#else
|
|
(void)usePulseAudioFlag; // avoid compiler warning
|
|
#endif
|
|
#ifdef USE_PORTAUDIO
|
|
if (usePortaudioFlag) {
|
|
driver = new Portaudio(seq);
|
|
if (!driver->init()) {
|
|
qDebug("init PortAudio failed");
|
|
delete driver;
|
|
driver = 0;
|
|
}
|
|
else
|
|
portAudioIsUsed = true;
|
|
}
|
|
#else
|
|
(void)usePortaudioFlag; // avoid compiler warning
|
|
#endif
|
|
#ifdef USE_ALSA
|
|
if (driver == 0 && useAlsaFlag) {
|
|
driver = new AlsaAudio(seq);
|
|
if (!driver->init()) {
|
|
qDebug("init ALSA driver failed");
|
|
delete driver;
|
|
driver = 0;
|
|
}
|
|
else {
|
|
alsaIsUsed = true;
|
|
}
|
|
}
|
|
#else
|
|
(void)useAlsaFlag; // avoid compiler warning
|
|
#endif
|
|
#ifdef USE_JACK
|
|
if (useJackFlag) {
|
|
useAlsaFlag = false;
|
|
usePortaudioFlag = false;
|
|
driver = new JackAudio(seq);
|
|
if (!driver->init()) {
|
|
qDebug("no JACK server found");
|
|
delete driver;
|
|
driver = 0;
|
|
}
|
|
else
|
|
jackIsUsed = true;
|
|
}
|
|
#else
|
|
(void)useJackFlag; // avoid compiler warning
|
|
#endif
|
|
#endif
|
|
if (driver == 0)
|
|
qDebug("no audio driver found");
|
|
|
|
return driver;
|
|
}
|
|
|
|
}
|
|
|