From 25ffa58d17f9174892a0694e111f05da8fbdcf70 Mon Sep 17 00:00:00 2001 From: SpellVif Date: Sat, 5 Dec 2020 22:13:12 +0100 Subject: [PATCH 1/3] Added a static function to MidiApi to be able to stop printing warnings and errors to the console. This is especially useful when RtMidi object is initialised with no device connected yet, we don't necessary want a warning being printed. --- RtMidi.cpp | 12 ++++++++++-- RtMidi.h | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/RtMidi.cpp b/RtMidi.cpp index 781d5b7c..250c46ee 100644 --- a/RtMidi.cpp +++ b/RtMidi.cpp @@ -533,6 +533,12 @@ RtMidiOut :: ~RtMidiOut() throw() //*********************************************************************// // Common MidiApi Definitions //*********************************************************************// +bool MidiApi :: printErrorIfNoCallback_ = false; + +void MidiApi:: printErrorIfNoCallback(bool print) +{ + printErrorIfNoCallback_ = print; +}; MidiApi :: MidiApi( void ) : apiData_( 0 ), connected_( false ), errorCallback_(0), firstErrorOccurred_(false), errorCallbackUserData_(0) @@ -565,7 +571,8 @@ void MidiApi :: error( RtMidiError::Type type, std::string errorString ) } if ( type == RtMidiError::WARNING ) { - std::cerr << '\n' << errorString << "\n\n"; + if ( printErrorIfNoCallback_ ) + std::cerr << '\n' << errorString << "\n\n"; } else if ( type == RtMidiError::DEBUG_WARNING ) { #if defined(__RTMIDI_DEBUG__) @@ -573,7 +580,8 @@ void MidiApi :: error( RtMidiError::Type type, std::string errorString ) #endif } else { - std::cerr << '\n' << errorString << "\n\n"; + if (printErrorIfNoCallback_) + std::cerr << '\n' << errorString << "\n\n"; throw RtMidiError( errorString, type ); } } diff --git a/RtMidi.h b/RtMidi.h index 9fc520ed..0876214f 100644 --- a/RtMidi.h +++ b/RtMidi.h @@ -496,6 +496,12 @@ class RTMIDI_DLL_PUBLIC MidiApi { public: + //! Set a boolean to avoid printing error messages to the error stream when no error callback is setup. + /*! + \param print True to print error messages to the error stream when no callback setup, false to not do so. + */ + static void printErrorIfNoCallback(bool print);; + MidiApi(); virtual ~MidiApi(); virtual RtMidi::Api getCurrentApi( void ) = 0; @@ -517,6 +523,7 @@ class RTMIDI_DLL_PUBLIC MidiApi protected: virtual void initialize( const std::string& clientName ) = 0; + static bool printErrorIfNoCallback_; void *apiData_; bool connected_; std::string errorString_; From 35070f6661a2b705282ed153f191a1e51a9df374 Mon Sep 17 00:00:00 2001 From: SpellVif Date: Sat, 5 Dec 2020 22:35:04 +0100 Subject: [PATCH 2/3] Corrected coding style. --- RtMidi.cpp | 2 +- RtMidi.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/RtMidi.cpp b/RtMidi.cpp index 250c46ee..a80752af 100644 --- a/RtMidi.cpp +++ b/RtMidi.cpp @@ -535,7 +535,7 @@ RtMidiOut :: ~RtMidiOut() throw() //*********************************************************************// bool MidiApi :: printErrorIfNoCallback_ = false; -void MidiApi:: printErrorIfNoCallback(bool print) +void MidiApi :: printErrorIfNoCallback( bool print ) { printErrorIfNoCallback_ = print; }; diff --git a/RtMidi.h b/RtMidi.h index 0876214f..5aa01970 100644 --- a/RtMidi.h +++ b/RtMidi.h @@ -500,7 +500,7 @@ class RTMIDI_DLL_PUBLIC MidiApi /*! \param print True to print error messages to the error stream when no callback setup, false to not do so. */ - static void printErrorIfNoCallback(bool print);; + static void printErrorIfNoCallback( bool print ); MidiApi(); virtual ~MidiApi(); From 4d9cc3310b72cd33bd35927ebf22ef1d836441b4 Mon Sep 17 00:00:00 2001 From: SpellVif Date: Sat, 5 Dec 2020 22:39:38 +0100 Subject: [PATCH 3/3] Corrected coding style. --- RtMidi.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/RtMidi.cpp b/RtMidi.cpp index a80752af..93d40538 100644 --- a/RtMidi.cpp +++ b/RtMidi.cpp @@ -537,8 +537,8 @@ bool MidiApi :: printErrorIfNoCallback_ = false; void MidiApi :: printErrorIfNoCallback( bool print ) { - printErrorIfNoCallback_ = print; -}; + printErrorIfNoCallback_ = print; +} MidiApi :: MidiApi( void ) : apiData_( 0 ), connected_( false ), errorCallback_(0), firstErrorOccurred_(false), errorCallbackUserData_(0) @@ -571,8 +571,8 @@ void MidiApi :: error( RtMidiError::Type type, std::string errorString ) } if ( type == RtMidiError::WARNING ) { - if ( printErrorIfNoCallback_ ) - std::cerr << '\n' << errorString << "\n\n"; + if ( printErrorIfNoCallback_ ) + std::cerr << '\n' << errorString << "\n\n"; } else if ( type == RtMidiError::DEBUG_WARNING ) { #if defined(__RTMIDI_DEBUG__) @@ -580,7 +580,7 @@ void MidiApi :: error( RtMidiError::Type type, std::string errorString ) #endif } else { - if (printErrorIfNoCallback_) + if ( printErrorIfNoCallback_ ) std::cerr << '\n' << errorString << "\n\n"; throw RtMidiError( errorString, type ); }