gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

AutoSystem.hxx (1583B)


      1 #ifndef INCLUDED_PORTAUDIO_AUTOSYSTEM_HXX
      2 #define INCLUDED_PORTAUDIO_AUTOSYSTEM_HXX
      3 
      4 // ---------------------------------------------------------------------------------------
      5 
      6 #include "portaudiocpp/System.hxx"
      7 
      8 // ---------------------------------------------------------------------------------------
      9 
     10 namespace portaudio
     11 {
     12 
     13 
     14 	//////
     15 	/// @brief A RAII idiom class to ensure automatic clean-up when an exception is 
     16 	/// raised.
     17 	///
     18 	/// A simple helper class which uses the 'Resource Acquisition is Initialization' 
     19 	/// idiom (RAII). Use this class to initialize/terminate the System rather than 
     20 	/// using System directly. AutoSystem must be created on stack and must be valid 
     21 	/// throughout the time you wish to use PortAudioCpp. Your 'main' function might be 
     22 	/// a good place for it.
     23 	///
     24 	/// To avoid having to type portaudio::System::instance().xyz() all the time, it's usually 
     25 	/// a good idea to make a reference to the System which can be accessed directly.
     26 	/// @verbatim
     27 	/// portaudio::AutoSys autoSys;
     28 	/// portaudio::System &sys = portaudio::System::instance();
     29 	/// @endverbatim
     30 	//////
     31 	class AutoSystem
     32 	{
     33 	public:
     34 		AutoSystem(bool initialize = true)
     35 		{
     36 			if (initialize)
     37 				System::initialize();
     38 		}
     39 
     40 		~AutoSystem()
     41 		{
     42 			if (System::exists())
     43 				System::terminate();
     44 		}
     45 
     46 		void initialize()
     47 		{
     48 			System::initialize();
     49 		}
     50 
     51 		void terminate()
     52 		{
     53 			System::terminate();
     54 		}
     55 	};
     56 
     57 
     58 } // namespace portaudio
     59 
     60 // ---------------------------------------------------------------------------------------
     61 
     62 #endif // INCLUDED_PORTAUDIO_AUTOSYSTEM_HXX