00001 /*---------------------------------------------------------------------------- 00002 MoMu: A Mobile Music Toolkit 00003 Copyright (c) 2010 Nicholas J. Bryan, Jorge Herrera, Jieun Oh, and Ge Wang 00004 All rights reserved. 00005 http://momu.stanford.edu/toolkit/ 00006 00007 Mobile Music Research @ CCRMA 00008 Music, Computing, Design Group 00009 Stanford University 00010 http://momu.stanford.edu/ 00011 http://ccrma.stanford.edu/groups/mcd/ 00012 00013 MoMu is distributed under the following BSD style open source license: 00014 00015 Permission is hereby granted, free of charge, to any person obtaining a 00016 copy of this software and associated documentation files (the 00017 "Software"), to deal in the Software without restriction, including 00018 without limitation the rights to use, copy, modify, merge, publish, 00019 distribute, sublicense, and/or sell copies of the Software, and to 00020 permit persons to whom the Software is furnished to do so, subject to 00021 the following conditions: 00022 00023 The authors encourage users of MoMu to include this copyright notice, 00024 and to let us know that you are using MoMu. Any person wishing to 00025 distribute modifications to the Software is encouraged to send the 00026 modifications to the original authors so that they can be incorporated 00027 into the canonical version. 00028 00029 The Software is provided "as is", WITHOUT ANY WARRANTY, express or implied, 00030 including but not limited to the warranties of MERCHANTABILITY, FITNESS 00031 FOR A PARTICULAR PURPOSE and NONINFRINGEMENT. In no event shall the authors 00032 or copyright holders by liable for any claim, damages, or other liability, 00033 whether in an actino of a contract, tort or otherwise, arising from, out of 00034 or in connection with the Software or the use or other dealings in the 00035 software. 00036 -----------------------------------------------------------------------------*/ 00037 00038 /*----------------------------------------------------------------------------*/ 00050 /*----------------------------------------------------------------------------*/ 00051 00052 #ifndef __MO_ACCEL_H__ 00053 #define __MO_ACCEL_H__ 00054 00055 #include "mo_def.h" 00056 #include <vector> 00057 00058 00059 /*----------------------------------------------------------------------------*/ 00064 /*----------------------------------------------------------------------------*/ 00065 @interface AccelDelegate : NSObject <UIAccelerometerDelegate> 00066 { } 00067 @end 00068 00069 00070 /*----------------------------------------------------------------------------*/ 00079 /*----------------------------------------------------------------------------*/ 00080 typedef void (* MoAccelCallback)( double x, double y, double z, void * data ); 00081 00082 00083 /*----------------------------------------------------------------------------*/ 00096 /*----------------------------------------------------------------------------*/ 00097 class MoAccel 00098 { 00099 public: // setting values 00100 00102 static void setUpdateInterval( double seconds ); 00104 static double getUpdateInterval(); 00105 00106 public: // getting values 00107 00109 static void getXYZ( double & px, double & py, double & pz ); 00111 static double getX(); 00113 static double getY(); 00115 static double getZ(); 00116 00117 public: // callbacks 00118 00120 static void addCallback( const MoAccelCallback & callback, void * data ); 00122 static void removeCallback( const MoAccelCallback & callback ); 00124 static const double MAX_ACCEL_RATE; 00125 00126 public: 00128 static void update( double x, double y, double z ); 00129 00130 private: 00131 // check if one time set up is needed 00132 static void checkSetup(); 00133 00134 // current values; 00135 static double m_x; 00136 static double m_y; 00137 static double m_z; 00138 00139 // update interval 00140 static double m_updateInterval; 00141 00142 // accelerometer Delegate 00143 static AccelDelegate * accelDelegate; 00144 00145 // queue of callbacks 00146 static std::vector<MoAccelCallback> m_clients; 00147 static std::vector<void *> m_clientData; 00148 00149 }; 00150 00151 00152 #endif