remove exception handling form MidiTest/rtMidi

add Mac OSX defines/linking frameworks for rtMidi
This commit is contained in:
Erwin Coumans 2013-03-31 16:02:04 -07:00
parent cee546b51e
commit e0254539a6
4 changed files with 97 additions and 55 deletions

View File

@ -45,7 +45,7 @@
// RtMidi Definitions // RtMidi Definitions
//*********************************************************************// //*********************************************************************//
void RtMidi :: getCompiledApi( std::vector<RtMidi::Api> &apis ) throw() void RtMidi :: getCompiledApi( std::vector<RtMidi::Api> &apis )
{ {
apis.clear(); apis.clear();
@ -69,6 +69,7 @@ void RtMidi :: getCompiledApi( std::vector<RtMidi::Api> &apis ) throw()
#if defined(__RTMIDI_DUMMY__) #if defined(__RTMIDI_DUMMY__)
apis.push_back( RTMIDI_DUMMY ); apis.push_back( RTMIDI_DUMMY );
#endif #endif
} }
void RtMidi :: error( RtError::Type type, std::string errorString ) void RtMidi :: error( RtError::Type type, std::string errorString )
@ -155,7 +156,7 @@ RtMidiIn :: RtMidiIn( RtMidi::Api api, const std::string clientName, unsigned in
RtMidi::error( RtError::WARNING, "RtMidiIn: no compiled API support found ... critical error!!" ); RtMidi::error( RtError::WARNING, "RtMidiIn: no compiled API support found ... critical error!!" );
} }
RtMidiIn :: ~RtMidiIn() throw() RtMidiIn :: ~RtMidiIn()
{ {
delete rtapi_; delete rtapi_;
} }
@ -229,7 +230,7 @@ RtMidiOut :: RtMidiOut( RtMidi::Api api, const std::string clientName )
RtMidi::error( RtError::WARNING, "RtMidiOut: no compiled API support found ... critical error!!" ); RtMidi::error( RtError::WARNING, "RtMidiOut: no compiled API support found ... critical error!!" );
} }
RtMidiOut :: ~RtMidiOut() throw() RtMidiOut :: ~RtMidiOut()
{ {
delete rtapi_; delete rtapi_;
} }
@ -2421,16 +2422,21 @@ public:
DestroyLists(); DestroyLists();
if (categories == 0) if (categories == 0)
throw std::runtime_error("CKsEnumFilters: invalid argument"); {
printf ("Error: CKsEnumFilters: invalid argument\n");
assert(0);
}
// Get a handle to the device set specified by the guid // Get a handle to the device set specified by the guid
HDEVINFO hDevInfo = ::SetupDiGetClassDevs(&categories[0], NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); HDEVINFO hDevInfo = ::SetupDiGetClassDevs(&categories[0], NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (!IsValid(hDevInfo)) if (!IsValid(hDevInfo))
throw std::runtime_error("CKsEnumFilters: no devices found"); {
printf ("Error: CKsEnumFilters: no devices found");
assert (0);
}
// Loop through members of the set and get details for each // Loop through members of the set and get details for each
for (int iClassMember=0;;iClassMember++) { for (int iClassMember=0;;iClassMember++) {
try { {
SP_DEVICE_INTERFACE_DATA DID; SP_DEVICE_INTERFACE_DATA DID;
DID.cbSize = sizeof(DID); DID.cbSize = sizeof(DID);
DID.Reserved = 0; DID.Reserved = 0;
@ -2442,15 +2448,19 @@ public:
// Get filter friendly name // Get filter friendly name
HKEY hRegKey = ::SetupDiOpenDeviceInterfaceRegKey(hDevInfo, &DID, 0, KEY_READ); HKEY hRegKey = ::SetupDiOpenDeviceInterfaceRegKey(hDevInfo, &DID, 0, KEY_READ);
if (hRegKey == INVALID_HANDLE_VALUE) if (hRegKey == INVALID_HANDLE_VALUE)
throw std::runtime_error("CKsEnumFilters: interface has no registry"); {
assert(0);
printf "CKsEnumFilters: interface has no registry\n");
}
char friendlyName[256]; char friendlyName[256];
DWORD dwSize = sizeof friendlyName; DWORD dwSize = sizeof friendlyName;
LONG lval = ::RegQueryValueEx(hRegKey, TEXT("FriendlyName"), NULL, NULL, (LPBYTE)friendlyName, &dwSize); LONG lval = ::RegQueryValueEx(hRegKey, TEXT("FriendlyName"), NULL, NULL, (LPBYTE)friendlyName, &dwSize);
::RegCloseKey(hRegKey); ::RegCloseKey(hRegKey);
if (lval != ERROR_SUCCESS) if (lval != ERROR_SUCCESS)
throw std::runtime_error("CKsEnumFilters: interface has no friendly name"); {
assert(0);
printf ("CKsEnumFilters: interface has no friendly name");
}
// Get details for the device registered in this class // Get details for the device registered in this class
DWORD const cbItfDetails = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA) + MAX_PATH * sizeof(WCHAR); DWORD const cbItfDetails = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA) + MAX_PATH * sizeof(WCHAR);
std::vector<BYTE> buffer(cbItfDetails); std::vector<BYTE> buffer(cbItfDetails);
@ -2464,8 +2474,10 @@ public:
fRes = ::SetupDiGetDeviceInterfaceDetail(hDevInfo, &DID, pDevInterfaceDetails, cbItfDetails, NULL, &DevInfoData); fRes = ::SetupDiGetDeviceInterfaceDetail(hDevInfo, &DID, pDevInterfaceDetails, cbItfDetails, NULL, &DevInfoData);
if (!fRes) if (!fRes)
throw std::runtime_error("CKsEnumFilters: could not get interface details"); {
printf("CKsEnumFilters: could not get interface details");
assert(0);
}
// check additional category guids which may (or may not) have been supplied // check additional category guids which may (or may not) have been supplied
for (size_t i=1; i < numCategories; ++i) { for (size_t i=1; i < numCategories; ++i) {
SP_DEVICE_INTERFACE_DATA DIDAlias; SP_DEVICE_INTERFACE_DATA DIDAlias;
@ -2474,11 +2486,16 @@ public:
fRes = ::SetupDiGetDeviceInterfaceAlias(hDevInfo, &DID, &categories[i], &DIDAlias); fRes = ::SetupDiGetDeviceInterfaceAlias(hDevInfo, &DID, &categories[i], &DIDAlias);
if (!fRes) if (!fRes)
throw std::runtime_error("CKsEnumFilters: could not get interface alias"); {
printf("CKsEnumFilters: could not get interface alias");
assert(0);
}
// Check if the this interface alias is enabled. // Check if the this interface alias is enabled.
if (!DIDAlias.Flags || (DIDAlias.Flags & SPINT_REMOVED)) if (!DIDAlias.Flags || (DIDAlias.Flags & SPINT_REMOVED))
throw std::runtime_error("CKsEnumFilters: interface alias is not enabled"); {
printf("CKsEnumFilters: interface alias is not enabled");
assert(0);
}
} }
std::auto_ptr<TFilterType> pFilter(new TFilterType(pDevInterfaceDetails->DevicePath, friendlyName)); std::auto_ptr<TFilterType> pFilter(new TFilterType(pDevInterfaceDetails->DevicePath, friendlyName));
@ -2489,8 +2506,6 @@ public:
m_Filters.push_back(pFilter.release()); m_Filters.push_back(pFilter.release());
} }
catch (std::runtime_error const& e) {
}
} }
::SetupDiDestroyDeviceInfoList(hDevInfo); ::SetupDiDestroyDeviceInfoList(hDevInfo);
@ -2698,7 +2713,10 @@ CKsFilter::CKsFilter(tstring const& sName, std::string const& sFriendlyName) :
m_sName(sName) m_sName(sName)
{ {
if (sName.empty()) if (sName.empty())
throw std::runtime_error("CKsFilter::CKsFilter: name can't be empty"); {
printf("CKsFilter::CKsFilter: name can't be empty");
assert(0);
}
} }
CKsFilter::~CKsFilter() CKsFilter::~CKsFilter()
@ -2794,8 +2812,10 @@ void CKsPin::SetState(KSSTATE ksState)
void CKsPin::Instantiate() void CKsPin::Instantiate()
{ {
if (!m_pKsPinConnect) if (!m_pKsPinConnect)
throw std::runtime_error("CKsPin::Instanciate: abstract pin"); {
printf("CKsPin::Instanciate: abstract pin");
assert(0);
}
DWORD const dwResult = KsCreatePin(m_pFilter->m_handle, m_pKsPinConnect, GENERIC_WRITE | GENERIC_READ, &m_handle); DWORD const dwResult = KsCreatePin(m_pFilter->m_handle, m_pKsPinConnect, GENERIC_WRITE | GENERIC_READ, &m_handle);
if (dwResult != ERROR_SUCCESS) if (dwResult != ERROR_SUCCESS)
throw ComException("CKsMidiCapFilter::CreateRenderPin: Pin instanciation failed", HRESULT_FROM_WIN32(dwResult)); throw ComException("CKsMidiCapFilter::CreateRenderPin: Pin instanciation failed", HRESULT_FROM_WIN32(dwResult));
@ -2863,7 +2883,10 @@ public:
void Validate() void Validate()
{ {
if (m_RenderPins.empty()) if (m_RenderPins.empty())
throw std::runtime_error("Could not find a MIDI render pin"); {
printf("Could not find a MIDI render pin");
assert(0);
}
} }
}; };
@ -2876,7 +2899,10 @@ public:
void Validate() void Validate()
{ {
if (m_CapturePins.empty()) if (m_CapturePins.empty())
throw std::runtime_error("Could not find a MIDI capture pin"); {
assert(0);
printf("Could not find a MIDI capture pin");
}
} }
}; };
@ -2890,16 +2916,17 @@ void CKsMidiFilter::FindMidiPins()
ULONG numPins = GetPinProperty<ULONG>(0, KSPROPERTY_PIN_CTYPES); ULONG numPins = GetPinProperty<ULONG>(0, KSPROPERTY_PIN_CTYPES);
for (ULONG iPin = 0; iPin < numPins; ++iPin) { for (ULONG iPin = 0; iPin < numPins; ++iPin) {
try { {
KSPIN_COMMUNICATION com = GetPinProperty<KSPIN_COMMUNICATION>(iPin, KSPROPERTY_PIN_COMMUNICATION); KSPIN_COMMUNICATION com = GetPinProperty<KSPIN_COMMUNICATION>(iPin, KSPROPERTY_PIN_COMMUNICATION);
if (com != KSPIN_COMMUNICATION_SINK && com != KSPIN_COMMUNICATION_BOTH) if (com != KSPIN_COMMUNICATION_SINK && com != KSPIN_COMMUNICATION_BOTH)
throw std::runtime_error("Unknown pin communication value"); {
printf("Unknown pin communication value");
assert(0);
}
m_Pins.push_back(new CKsMidiPin(this, iPin)); m_Pins.push_back(new CKsMidiPin(this, iPin));
} }
catch (std::runtime_error const&) {
// pin instanciation has failed, continue to the next pin.
}
} }
m_RenderPins.clear(); m_RenderPins.clear();
@ -2917,7 +2944,11 @@ void CKsMidiFilter::FindMidiPins()
} }
if (m_RenderPins.empty() && m_CapturePins.empty()) if (m_RenderPins.empty() && m_CapturePins.empty())
throw std::runtime_error("No valid pins found on the filter."); {
printf("No valid pins found on the filter.");
assert(0);
}
} }
CKsMidiRenFilter::CKsMidiRenFilter(tstring const& sPath, std::string const& sFriendlyName) : CKsMidiRenFilter::CKsMidiRenFilter(tstring const& sPath, std::string const& sFriendlyName) :
@ -2928,7 +2959,10 @@ CKsMidiRenFilter::CKsMidiRenFilter(tstring const& sPath, std::string const& sFri
CKsMidiPin* CKsMidiRenFilter::CreateRenderPin() CKsMidiPin* CKsMidiRenFilter::CreateRenderPin()
{ {
if (m_RenderPins.empty()) if (m_RenderPins.empty())
throw std::runtime_error("Could not find a MIDI render pin"); {
printf("Could not find a MIDI render pin");
assert(0);
}
CKsMidiPin* pPin = (CKsMidiPin*)m_RenderPins[0]; CKsMidiPin* pPin = (CKsMidiPin*)m_RenderPins[0];
pPin->Instantiate(); pPin->Instantiate();
@ -2943,8 +2977,10 @@ CKsMidiCapFilter::CKsMidiCapFilter(tstring const& sPath, std::string const& sFri
CKsMidiPin* CKsMidiCapFilter::CreateCapturePin() CKsMidiPin* CKsMidiCapFilter::CreateCapturePin()
{ {
if (m_CapturePins.empty()) if (m_CapturePins.empty())
throw std::runtime_error("Could not find a MIDI capture pin"); {
printf("Could not find a MIDI capture pin");
assert(0);
}
CKsMidiPin* pPin = (CKsMidiPin*)m_CapturePins[0]; CKsMidiPin* pPin = (CKsMidiPin*)m_CapturePins[0];
pPin->Instantiate(); pPin->Instantiate();
return pPin; return pPin;
@ -2993,10 +3029,16 @@ CKsMidiPin::CKsMidiPin(CKsFilter* pFilter, ULONG nId) :
} }
if (!hasStdStreamingInterface) // No standard streaming interfaces on the pin if (!hasStdStreamingInterface) // No standard streaming interfaces on the pin
throw std::runtime_error("CKsMidiPin::CKsMidiPin: no standard streaming interface"); {
printf("CKsMidiPin::CKsMidiPin: no standard streaming interface");
assert(0);
}
if (!hasStdStreamingMedium) // No standard streaming mediums on the pin if (!hasStdStreamingMedium) // No standard streaming mediums on the pin
throw std::runtime_error("CKsMidiPin::CKsMidiPin: no standard streaming medium"); {
printf("CKsMidiPin::CKsMidiPin: no standard streaming medium")
assert(0);
};
bool hasMidiDataRange = false; bool hasMidiDataRange = false;
@ -3014,7 +3056,10 @@ CKsMidiPin::CKsMidiPin(CKsFilter* pFilter, ULONG nId) :
} }
if (!hasMidiDataRange) // No MIDI dataranges on the pin if (!hasMidiDataRange) // No MIDI dataranges on the pin
throw std::runtime_error("CKsMidiPin::CKsMidiPin: no MIDI datarange"); {
printf("CKsMidiPin::CKsMidiPin: no MIDI datarange");
assert(0);
}
} }
@ -3134,13 +3179,11 @@ void MidiInWinKS :: initialize( const std::string& clientName )
MidiInWinKS :: ~MidiInWinKS() MidiInWinKS :: ~MidiInWinKS()
{ {
WindowsKsData* data = static_cast<WindowsKsData*>(apiData_); WindowsKsData* data = static_cast<WindowsKsData*>(apiData_);
try { {
if ( data->m_pPin ) if ( data->m_pPin )
closePort(); closePort();
} }
catch(...) {
}
delete data; delete data;
} }

View File

@ -70,7 +70,7 @@ class RtMidi
the enumerated list values. Note that there can be more than one the enumerated list values. Note that there can be more than one
API compiled for certain operating systems. API compiled for certain operating systems.
*/ */
static void getCompiledApi( std::vector<RtMidi::Api> &apis ) throw(); static void getCompiledApi( std::vector<RtMidi::Api> &apis );
//! Pure virtual openPort() function. //! Pure virtual openPort() function.
virtual void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi" ) ) = 0; virtual void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi" ) ) = 0;
@ -140,7 +140,7 @@ class RtMidiIn : public RtMidi
//! Default constructor that allows an optional api, client name and queue size. //! Default constructor that allows an optional api, client name and queue size.
/*! /*!
An exception will be thrown if a MIDI system initialization An assert will be fired if a MIDI system initialization
error occurs. The queue size defines the maximum number of error occurs. The queue size defines the maximum number of
messages that can be held in the MIDI queue (when not using a messages that can be held in the MIDI queue (when not using a
callback function). If the queue size limit is reached, callback function). If the queue size limit is reached,
@ -155,10 +155,10 @@ class RtMidiIn : public RtMidi
unsigned int queueSizeLimit = 100 ); unsigned int queueSizeLimit = 100 );
//! If a MIDI connection is still open, it will be closed by the destructor. //! If a MIDI connection is still open, it will be closed by the destructor.
~RtMidiIn ( void ) throw(); ~RtMidiIn ( void );
//! Returns the MIDI API specifier for the current instance of RtMidiIn. //! Returns the MIDI API specifier for the current instance of RtMidiIn.
RtMidi::Api getCurrentApi( void ) throw(); RtMidi::Api getCurrentApi( void );
//! Open a MIDI input connection. //! Open a MIDI input connection.
/*! /*!
@ -218,7 +218,7 @@ class RtMidiIn : public RtMidi
/*! /*!
This function returns immediately whether a new message is This function returns immediately whether a new message is
available or not. A valid message is indicated by a non-zero available or not. A valid message is indicated by a non-zero
vector size. An exception is thrown if an error occurs during vector size. An assert is fired if an error occurs during
message retrieval or an input connection was not previously message retrieval or an input connection was not previously
established. established.
*/ */
@ -262,10 +262,10 @@ class RtMidiOut : public RtMidi
const std::string clientName = std::string( "RtMidi Output Client") ); const std::string clientName = std::string( "RtMidi Output Client") );
//! The destructor closes any open MIDI connections. //! The destructor closes any open MIDI connections.
~RtMidiOut( void ) throw(); ~RtMidiOut( void );
//! Returns the MIDI API specifier for the current instance of RtMidiOut. //! Returns the MIDI API specifier for the current instance of RtMidiOut.
RtMidi::Api getCurrentApi( void ) throw(); RtMidi::Api getCurrentApi( void );
//! Open a MIDI output connection. //! Open a MIDI output connection.
/*! /*!
@ -423,7 +423,7 @@ class MidiOutApi
// //
// **************************************************************** // // **************************************************************** //
inline RtMidi::Api RtMidiIn :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); } inline RtMidi::Api RtMidiIn :: getCurrentApi( void ) { return rtapi_->getCurrentApi(); }
inline void RtMidiIn :: openPort( unsigned int portNumber, const std::string portName ) { return rtapi_->openPort( portNumber, portName ); } inline void RtMidiIn :: openPort( unsigned int portNumber, const std::string portName ) { return rtapi_->openPort( portNumber, portName ); }
inline void RtMidiIn :: openVirtualPort( const std::string portName ) { return rtapi_->openVirtualPort( portName ); } inline void RtMidiIn :: openVirtualPort( const std::string portName ) { return rtapi_->openVirtualPort( portName ); }
inline void RtMidiIn :: closePort( void ) { return rtapi_->closePort(); } inline void RtMidiIn :: closePort( void ) { return rtapi_->closePort(); }
@ -434,7 +434,7 @@ inline std::string RtMidiIn :: getPortName( unsigned int portNumber ) { return r
inline void RtMidiIn :: ignoreTypes( bool midiSysex, bool midiTime, bool midiSense ) { return rtapi_->ignoreTypes( midiSysex, midiTime, midiSense ); } inline void RtMidiIn :: ignoreTypes( bool midiSysex, bool midiTime, bool midiSense ) { return rtapi_->ignoreTypes( midiSysex, midiTime, midiSense ); }
inline double RtMidiIn :: getMessage( std::vector<unsigned char> *message ) { return rtapi_->getMessage( message ); } inline double RtMidiIn :: getMessage( std::vector<unsigned char> *message ) { return rtapi_->getMessage( message ); }
inline RtMidi::Api RtMidiOut :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); } inline RtMidi::Api RtMidiOut :: getCurrentApi( void ) { return rtapi_->getCurrentApi(); }
inline void RtMidiOut :: openPort( unsigned int portNumber, const std::string portName ) { return rtapi_->openPort( portNumber, portName ); } inline void RtMidiOut :: openPort( unsigned int portNumber, const std::string portName ) { return rtapi_->openPort( portNumber, portName ); }
inline void RtMidiOut :: openVirtualPort( const std::string portName ) { return rtapi_->openVirtualPort( portName ); } inline void RtMidiOut :: openVirtualPort( const std::string portName ) { return rtapi_->openVirtualPort( portName ); }
inline void RtMidiOut :: closePort( void ) { return rtapi_->closePort(); } inline void RtMidiOut :: closePort( void ) { return rtapi_->closePort(); }
@ -638,7 +638,7 @@ class MidiOutWinKS: public MidiOutApi
#endif #endif
#if defined(__RTMIDI_DUMMY__) #if defined(__RTMIDI_DUMMY__)
aa
class MidiInDummy: public MidiInApi class MidiInDummy: public MidiInApi
{ {
public: public:

View File

@ -40,7 +40,6 @@ int main( int argc, char *argv[] )
// Minimal command-line check. // Minimal command-line check.
if ( argc > 2 ) usage(); if ( argc > 2 ) usage();
try {
// RtMidiIn constructor // RtMidiIn constructor
midiin = new RtMidiIn(); midiin = new RtMidiIn();
@ -59,10 +58,8 @@ int main( int argc, char *argv[] )
std::cout << "\nReading MIDI input ... press <enter> to quit.\n"; std::cout << "\nReading MIDI input ... press <enter> to quit.\n";
char input; char input;
std::cin.get(input); std::cin.get(input);
getchar();
} catch ( RtError &error ) {
error.printMessage();
}
cleanup: cleanup:

View File

@ -29,5 +29,7 @@
end end
if os.is("MacOSX") then if os.is("MacOSX") then
links{"Cocoa.framework"} links{"CoreAudio.framework", "coreMIDI.framework", "Cocoa.framework"}
defines {"__MACOSX_CORE__"}
print ("hi!")
end end