VISR  0.11.8
Versatile Interactive Scene Renderer
external_wrapper.hpp
Go to the documentation of this file.
1 /* Copyright Institute of Sound and Vibration Research - All rights reserved */
2 
3 #ifndef VISR_MAXMSP_MAXSUPPORT_EXTERNAL_WRAPPER_HPP_INCLUDED
4 #define VISR_MAXMSP_MAXSUPPORT_EXTERNAL_WRAPPER_HPP_INCLUDED
5 
6 #include <sstream>
7 
8 /* Super-safe determination of the MAX define for setting the operating system. */
9 #ifdef __APPLE_CC__
10 #ifndef MAC_VERSION
11 #define MAC_VERSION
12 #undef WIN_VERSION
13 #endif
14 #else
15 #ifdef _MSC_VER
16 #ifndef WIN_VERSION
17 #define WIN_VERSION
18 #endif
19 #undef MAC_VERSION
20 #endif
21 #endif
22 
23 #include <ext.h>
24 #include <ext_obex.h>
25 #include "z_dsp.h"
26 
27 namespace visr
28 {
29 namespace maxmsp
30 {
31 
32 // Forward declaration
33 template<class ExternalType> class ClassRegistrar;
34 
35 template<class ExternalClass>
37 {
38  template<class ExternalType>
39  friend class ClassRegistrar;
40 private:
41 
42  struct PlainObject
43  {
44  public:
52  t_pxobject mMaxProxy;
53 
58  ExternalClass* mObject;
59  };
60 
61  static void dsp64( PlainObject *obj, t_object *dsp64, short *count, double samplerate, long maxvectorsize, long flags );
62 
63  static void perform64( PlainObject *x, t_object *dsp64, double **ins,
64  long numins, double **outs, long numouts,
65  long sampleframes, long flags, void *userparam );
66 
67  static void free( PlainObject *x );
68 
69  static void assist( PlainObject *x, void *b, long msg, long arg, char *dst );
70 
71  static void getFloat( PlainObject *x, double f );
72 
73  PlainObject* mPlainStruct;
74 };
75 
76 template<class ExternalClass>
77 /*static*/ void ExternalWrapper<ExternalClass>::dsp64( PlainObject *obj, t_object *dsp64, short *count, double samplerate, long maxvectorsize, long flags )
78 {
79  post( "ExternalWrapper<ExternalClass>::dsp64 called." );
80 
81  try
82  {
83  obj->mObject->initDsp( dsp64, count, samplerate, maxvectorsize, flags );
84  }
85  catch( std::exception const & ex )
86  {
87  std::stringstream errMsg;
88  errMsg << "maxmsp::ExternalWrapper: Error during dsp_add64(): " << ex.what( );
89  object_error( reinterpret_cast<t_object*>(obj), errMsg.str( ).c_str( ) );
90  }
91 
92  dsp_add64( dsp64, reinterpret_cast<t_object*>(obj), reinterpret_cast<t_perfroutine64>(&ExternalWrapper<ExternalClass>::perform64), 0, NULL );
93 }
94 
95 template<class ExternalClass>
96 /*static*/ void ExternalWrapper<ExternalClass>::perform64( PlainObject *x, t_object *dsp64, double **ins,
97  long numins, double **outs, long numouts,
98  long sampleframes, long flags, void *userparam )
99 {
100  x->mObject->perform( dsp64, ins, numins, outs, numouts, sampleframes, flags, userparam );
101 }
102 
103 template<class ExternalClass>
104 /*static*/ void ExternalWrapper<ExternalClass>::free( PlainObject* obj )
105 {
106  post( "ExternalWrapper<ExternalClass>::free() called." );
107  /* We must call dsp_free() before freeing any dynamic memory
108  allocated for the external. This removes the object from the Max/MSP DSP chain. */
109  dsp_free( &(obj->mMaxProxy) );
110  delete obj->mObject;
111 }
112 
113 template<class ExternalClass>
114 /*static*/ void ExternalWrapper<ExternalClass>::assist( PlainObject* obj, void *b, long msg, long arg, char *dst )
115 {
116  obj->mObject->assist( b, msg, arg, dst );
117 }
118 
119 template<class ExternalClass>
120 /*static*/ void ExternalWrapper<ExternalClass>::getFloat( PlainObject* obj, double f )
121 {
122  obj->mObject->getFloat( f );
123 }
124 
125 } // namespace visr
126 } // namespace maxmsp
127 
128 #endif // VISR_MAXMSP_MAXSUPPORT_EXTERNAL_WRAPPER_HPP_INCLUDED
Definition: class_registrar.hpp:31
Definition: options.cpp:10
Definition: external_wrapper.hpp:36