Tactons through library
authorThomas Pietrzak <thomas.pietrzak@gmail.com>
Tue, 14 Jun 2011 17:06:24 +0000 (17:06 +0000)
committerThomas Pietrzak <thomas.pietrzak@gmail.com>
Tue, 14 Jun 2011 17:06:24 +0000 (17:06 +0000)
git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@23 47cf9a05-e0a8-4ed5-9e9b-101a649bc004

Haptic Metronome/Haptic Metronome.suo
Haptic Metronome/Haptic Metronome/Haptic Metronome.vcxproj
Haptic Metronome/Haptic Metronome/Haptic Metronome.vcxproj.filters
include/MetronomeHaptic.hpp
include/Serial.hpp [deleted file]
include/SerialWindows.hpp [deleted file]
src/MetronomeHaptic.cpp
src/PaintGame.cpp
src/Serial.cpp [deleted file]
src/SerialWindows.cpp [deleted file]

index 78d1928eb70c21c149b796fcacfc0be99fc6df3f..57a05efe38d0732fe8572609b0448e5dc2963944 100644 (file)
Binary files a/Haptic Metronome/Haptic Metronome.suo and b/Haptic Metronome/Haptic Metronome.suo differ
index 861b312a091cb412d4652af767db707e891c1ba3..1fa4b81b7d089a575eb50da6464ddba37c68ef40 100644 (file)
@@ -57,7 +57,7 @@
     </ClCompile>\r
     <Link>\r
       <GenerateDebugInformation>true</GenerateDebugInformation>\r
-      <AdditionalDependencies>SDL.lib;SDLmain.lib;SDL_image.lib;SDL_mixer.lib;glew32.lib;opengl32.lib;glu32.lib;wiiuse.lib;Winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <AdditionalDependencies>TactonPlayer.lib;SDL.lib;SDLmain.lib;SDL_image.lib;SDL_mixer.lib;glew32.lib;opengl32.lib;glu32.lib;wiiuse.lib;Winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
       <SubSystem>Windows</SubSystem>\r
       <IgnoreSpecificDefaultLibraries>msvcrt.lib</IgnoreSpecificDefaultLibraries>\r
     </Link>\r
@@ -74,7 +74,7 @@
       <GenerateDebugInformation>false</GenerateDebugInformation>\r
       <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
       <OptimizeReferences>true</OptimizeReferences>\r
-      <AdditionalDependencies>SDL.lib;SDLmain.lib;SDL_image.lib;SDL_mixer.lib;glew32.lib;opengl32.lib;glu32.lib;wiiuse.lib;Winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <AdditionalDependencies>TactonPlayer.lib;SDL.lib;SDLmain.lib;SDL_image.lib;SDL_mixer.lib;glew32.lib;opengl32.lib;glu32.lib;wiiuse.lib;Winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
       <SubSystem>Windows</SubSystem>\r
     </Link>\r
   </ItemDefinitionGroup>\r
@@ -88,8 +88,6 @@
     <ClInclude Include="..\..\include\PaintGame.h" />\r
     <ClInclude Include="..\..\include\Pair.hpp" />\r
     <ClInclude Include="..\..\include\PrefixTree.hpp" />\r
-    <ClInclude Include="..\..\include\Serial.hpp" />\r
-    <ClInclude Include="..\..\include\SerialWindows.hpp" />\r
     <ClInclude Include="..\..\include\Sound.hpp" />\r
     <ClInclude Include="..\..\include\String.hpp" />\r
     <ClInclude Include="..\..\include\Texture.hpp" />\r
     <ClCompile Include="..\..\src\PaintGame.cpp" />\r
     <ClCompile Include="..\..\src\Pair.cpp" />\r
     <ClCompile Include="..\..\src\PrefixTree.cpp" />\r
-    <ClCompile Include="..\..\src\Serial.cpp" />\r
-    <ClCompile Include="..\..\src\SerialWindows.cpp" />\r
     <ClCompile Include="..\..\src\Sound.cpp" />\r
     <ClCompile Include="..\..\src\String.cpp" />\r
     <ClCompile Include="..\..\src\Texture.cpp" />\r
index 62ad99a8ccef7461484cdd3757fece8d69908510..58be612bc2bf42097a7dc0585755feb9f0ca0113 100644 (file)
     <ClInclude Include="..\..\include\MetronomeHaptic.hpp">\r
       <Filter>Header Files</Filter>\r
     </ClInclude>\r
-    <ClInclude Include="..\..\include\Serial.hpp">\r
-      <Filter>Header Files</Filter>\r
-    </ClInclude>\r
-    <ClInclude Include="..\..\include\SerialWindows.hpp">\r
-      <Filter>Header Files</Filter>\r
-    </ClInclude>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClCompile Include="..\..\src\Wiimote.cpp">\r
     <ClCompile Include="..\..\src\MetronomeHaptic.cpp">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
-    <ClCompile Include="..\..\src\Serial.cpp">\r
-      <Filter>Source Files</Filter>\r
-    </ClCompile>\r
-    <ClCompile Include="..\..\src\SerialWindows.cpp">\r
-      <Filter>Source Files</Filter>\r
-    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <None Include="ClassDiagram1.cd" />\r
index e402770a3bc983fbfd4abf034a17a4ec5c8d560f..35bc78fd1aa51300c9710d97b2d4cea1baddd820 100644 (file)
@@ -9,8 +9,7 @@
 
 #include <SDL/SDL.h>
 #include <SDL/SDL_Thread.h>
-
-#include "Serial.hpp"
+#include <TactonPlayer\TactonPlayer.hpp>
 \r
 class MetronomeHaptic : public Metronome\r
 {      \r
@@ -31,7 +30,7 @@ class MetronomeHaptic : public Metronome
        private:\r
                static int thread_func(void *unused);\r
                SDL_Thread *thread;\r
-               Serial *_comport;\r
+               TactonPlayer _tactonPlayer;\r
 };\r
 \r
 #endif\r
diff --git a/include/Serial.hpp b/include/Serial.hpp
deleted file mode 100644 (file)
index f306af7..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef _SERIAL_\r
-#define _SERIAL_\r
-\r
-#define ARDUINO_WAIT_TIME 500\r
-\r
-class Serial\r
-{\r
-    public:\r
-        //Initialize Serial communication with the given COM port\r
-        Serial(char *portName);\r
-\r
-        //Close the connection\r
-        //NOTA: for some reason you can't connect again before exiting\r
-        //the program and running it again\r
-        virtual ~Serial();\r
-\r
-        //Read data in a buffer, if nbChar is greater than the\r
-        //maximum number of bytes available, it will return only the\r
-        //bytes available. The function return -1 when nothing could\r
-        //be read, the number of bytes actually read.\r
-        virtual int ReadData(void *buffer, unsigned int nbChar)=0;\r
-\r
-        //Writes data from a buffer through the Serial connection\r
-        //return true on success.\r
-        virtual bool WriteData(void *buffer, unsigned int nbChar)=0;\r
-\r
-        //Check if we are actually connected\r
-               bool IsConnected() { return _connected; }\r
-\r
-    protected:\r
-        //Connection status\r
-        bool _connected;\r
-};\r
-\r
-#endif\r
diff --git a/include/SerialWindows.hpp b/include/SerialWindows.hpp
deleted file mode 100644 (file)
index 28eb1af..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef _SERIALWINDOWS_\r
-#define _SERIALWINDOWS_\r
-\r
-#include "Serial.hpp"\r
-\r
-#include <windows.h>\r
-\r
-class SerialWindows : public Serial\r
-{\r
-    public:\r
-        //Initialize Serial communication with the given COM port\r
-        SerialWindows(char *portName);\r
-        //Close the connection\r
-        //NOTA: for some reason you can't connect again before exiting\r
-        //the program and running it again\r
-        ~SerialWindows();\r
-        //Read data in a buffer, if nbChar is greater than the\r
-        //maximum number of bytes available, it will return only the\r
-        //bytes available. The function return -1 when nothing could\r
-        //be read, the number of bytes actually read.\r
-        int ReadData(void *buffer, unsigned int nbChar);\r
-        //Writes data from a buffer through the Serial connection\r
-        //return true on success.\r
-        bool WriteData(void *buffer, unsigned int nbChar);\r
-\r
-\r
-    private:\r
-        //Serial comm handler\r
-        HANDLE _hSerial;\r
-        //Get various information about the connection\r
-        COMSTAT _status;\r
-        //Keep track of last error\r
-        DWORD _errors;\r
-};\r
-#endif\r
index 164716972b05617c3bada2fc19c9664dad85b182..2093a6ad56bca0b7b39d3bfc1c1660fe2bc3ad3e 100644 (file)
@@ -4,62 +4,22 @@
 
 #include <SDL/SDL_mutex.h>
 
-#ifdef WIN32
-       #include "SerialWindows.hpp"
-#else
-       #include "SerialLinux.hpp"
-#endif
-
 #define BEFOREDELAY 2000
 
 extern Uint32 start;
 extern FILE *logfile;
 
 MetronomeHaptic::MetronomeHaptic(const Track &track, Uint32 nbbeats, Uint32 tempo, bool activated)
-:Metronome(track, nbbeats, tempo, activated), thread(NULL)
+:Metronome(track, nbbeats, tempo, activated), thread(NULL), _tactonPlayer("COM3")
 {
-       try
-       {
-                _comport = new SerialWindows("COM3");
-       }
-       catch (char *error)
-       {
-               SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s\n", error);
-                _comport = new SerialWindows("COM5");
-       }
-       unsigned char buffer1[3];\r
-       buffer1[0] = 'N'; buffer1[1] = 0x00; buffer1[2] = 0x01;\r
-       unsigned char buffer2[6];\r
-       buffer2[0] = 0x01;                                              //pattern\r
-       buffer2[1] = 0; buffer2[2] = 50;        //duration\r
-       buffer2[3] = 0; buffer2[4] = 250;               //frequency\r
-       buffer2[5] = 255;                                               //amplitude\r
-\r
-       //Tacton 1\r
-       _comport->WriteData(buffer1, 3);
-       _comport->WriteData(buffer2, 6);
-\r
-       //Tacton 2\r
-       buffer2[0] = 0x02;                                      //pattern\r
-       _comport->WriteData(buffer1, 3);
-       _comport->WriteData(buffer2, 6);
-\r
-       //Tacton 3\r
-       buffer2[0] = 0x04;                                      //pattern\r
-       _comport->WriteData(buffer1, 3);
-       _comport->WriteData(buffer2, 6);
-
-       //Tacton 4\r
-       buffer2[0] = 0x08;                                      //pattern\r
-       _comport->WriteData(buffer1, 3);
-       _comport->WriteData(buffer2, 6);
+       //load the tactons
+       _tactonPlayer.registFile("bips.txt");\r
 }
 
 MetronomeHaptic::~MetronomeHaptic()
 {
-       _comport->WriteData("Q", 1);
+       _tactonPlayer.stop();
        _activated = false;
-       delete _comport;
        SDL_WaitThread(thread, NULL);
 }
 
@@ -85,18 +45,10 @@ void MetronomeHaptic::init()
 
 void MetronomeHaptic::checkAt(Uint32 timestamp)
 {
-       unsigned char outBuffer[6];
-       outBuffer[0] = 'P';
-       
        //send first beeps in advance
        while (_iBips != _bips->end() && timestamp >= BIPTIMESTAMP(*_iBips))
        {
-               outBuffer[1] = _currentbeat % 4;\r
-               outBuffer[2] = (BIPTIMESTAMP(*_iBips) & 0xff000000) >> 24;\r
-               outBuffer[3] = (BIPTIMESTAMP(*_iBips) & 0x00ff0000) >> 16;\r
-               outBuffer[4] = (BIPTIMESTAMP(*_iBips) & 0x0000ff00) >> 8;\r
-               outBuffer[5] = BIPTIMESTAMP(*_iBips) & 0x000000ff;\r
-               bool written = _comport->WriteData(outBuffer, 6);\r
+               _tactonPlayer.schedule(_currentbeat % 4, BIPTIMESTAMP(*_iBips));\r
 
                if (logfile)
                        fprintf(logfile, "BIP;%d;%d;%d\n", BIPTICK(*_iBips), BIPTIMESTAMP(*_iBips), 0);
@@ -125,22 +77,11 @@ int MetronomeHaptic::thread_func(void *obj)
        MetronomeHaptic *thismetronome = static_cast<MetronomeHaptic *>(obj);
 
 //     SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
-
-       unsigned char outBuffer[6];
-       outBuffer[0] = 'P';
        
-       bool written = thismetronome->_comport->WriteData("S", 1);
+       thismetronome->_tactonPlayer.start();
 
        while(thismetronome->_activated)
        {
-               // TEST
-               char INBUFFER[128];\r
-               memset(INBUFFER, 0, 128);
-               int nbread = thismetronome->_comport->ReadData(INBUFFER, 128);
-               if (nbread > 0)
-                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "%d read: %s\n", nbread, INBUFFER);
-               //\r
-\r
                thismetronome->checkAt(SDL_GetTicks() - start + BEFOREDELAY);\r
 \r
                SDL_Delay(5);
index afa03b5ce16f5cc44de293bafe1029847027df49..791fa98139e2f9736003a4a3664f3374fe09eec5 100644 (file)
@@ -626,7 +626,7 @@ void loop(const Track &tr, const String &songname)
        Metronome *m = NULL, *m2 = NULL;
        try
        {
-               //m = new MetronomeHaptic(tr);
+               m = new MetronomeHaptic(tr);
                m2 = new MetronomeAudio(tr);
        }
        catch (char *error)
diff --git a/src/Serial.cpp b/src/Serial.cpp
deleted file mode 100644 (file)
index e527263..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#include "Serial.hpp"\r
-\r
-Serial::Serial(char *)\r
-:_connected(false)\r
-{\r
-}\r
-\r
-Serial::~Serial()\r
-{\r
-}\r
diff --git a/src/SerialWindows.cpp b/src/SerialWindows.cpp
deleted file mode 100644 (file)
index 584ff8c..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-#include "SerialWindows.hpp"\r
-\r
-#include <iostream>\r
-using namespace std;\r
-
-#ifdef WIN32
-#include <windows.h>
-#endif
-
-#include <SDL/SDL.h>
-\r
-SerialWindows::SerialWindows(char *portName)\r
-:Serial(portName)\r
-{\r
-    //Try to connect to the given port throuh CreateFile\r
-    _hSerial = CreateFile(portName,\r
-            GENERIC_READ | GENERIC_WRITE,\r
-            0,\r
-            NULL,\r
-            OPEN_EXISTING,\r
-            FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, //FILE_ATTRIBUTE_NORMAL,\r
-            NULL);\r
-\r
-    //Check if the connection was successfull\r
-    if(_hSerial == INVALID_HANDLE_VALUE)\r
-    {\r
-        //If not success full display an Error\r
-        if(GetLastError() == ERROR_FILE_NOT_FOUND)\r
-            SDL_LogError(SDL_LOG_CATEGORY_ERROR, "ERROR: Handle was not attached. Reason: %s not available.\n", portName);\r
-        else\r
-            cerr << "ERROR unknown" << endl;\r
-               char buffer[256];\r
-               sprintf(buffer, "Port %s does not exist or not reachable", portName);\r
-               throw buffer;\r
-    }\r
-    else\r
-    {\r
-       /*      
-       COMMTIMEOUTS commTimeouts;
-       commTimeouts.ReadIntervalTimeout = 1;
-       commTimeouts.ReadTotalTimeoutMultiplier = 10;
-       commTimeouts.ReadTotalTimeoutConstant = 100;
-       commTimeouts.WriteTotalTimeoutMultiplier = 10;
-       commTimeouts.WriteTotalTimeoutConstant = 100;
-       if (SetCommTimeouts(_comport, &commTimeouts) == 0)
-               throw "Cannot set COM port timeouts";*/
-\r
-\r
-        //If connected we try to set the comm parameters\r
-        DCB dcbSerialParams = {0};\r
-\r
-        //Try to get the current\r
-        if (!GetCommState(_hSerial, &dcbSerialParams))\r
-            //If impossible, show an error\r
-            SDL_LogError(SDL_LOG_CATEGORY_ERROR, "ERROR: failed to get current serial parameters!\n");\r
-        else\r
-        {\r
-            //Define serial connection parameters for the arduino board\r
-            dcbSerialParams.BaudRate=CBR_57600;\r
-            dcbSerialParams.ByteSize=8;\r
-            dcbSerialParams.StopBits=ONESTOPBIT;\r
-            dcbSerialParams.Parity=NOPARITY;\r
-\r
-             //Set the parameters and check for their proper application\r
-             if(!SetCommState(_hSerial, &dcbSerialParams))\r
-                SDL_LogError(SDL_LOG_CATEGORY_ERROR, "ERROR: Could not set Serial Port parameters\n");\r
-             else\r
-             {\r
-                 //If everything went fine we're connected\r
-                 _connected = true;\r
-                 //We wait 2s as the arduino board will be reseting\r
-                 SDL_Delay(ARDUINO_WAIT_TIME);\r
-             }\r
-        }\r
-    }\r
-}\r
-\r
-SerialWindows::~SerialWindows()\r
-{\r
-    //Check if we are connected before trying to disconnect\r
-    if(_connected)\r
-    {\r
-        //We're no longer connected\r
-        _connected = false;\r
-        //Close the serial handler\r
-        CloseHandle(_hSerial);\r
-    }\r
-}\r
-\r
-int SerialWindows::ReadData(void *buffer, unsigned int nbChar)\r
-{\r
-    //Number of bytes we'll have read\r
-    DWORD bytesRead = 0;\r
-    //Number of bytes we'll really ask to read\r
-    unsigned int toRead = 0;\r
-\r
-    //Use the ClearCommError function to get status info on the Serial port\r
-    ClearCommError(_hSerial, &_errors, &_status);\r
-\r
-    //Check if there is something to read\r
-    if(_status.cbInQue > 0)\r
-    {\r
-        //If there is we check if there is enough data to read the required number\r
-        //of characters, if not we'll read only the available characters to prevent\r
-        //locking of the application.\r
-        if(_status.cbInQue > nbChar)\r
-                       toRead = nbChar;\r
-        else\r
-                       toRead = _status.cbInQue;\r
-\r
-        //Try to read the require number of chars, and return the number of read bytes on success\r
-        if(ReadFile(_hSerial, buffer, toRead, &bytesRead, NULL) && bytesRead != 0)\r
-            return bytesRead;\r
-    }\r
-\r
-    //If nothing has been read, or that an error was detected return -1\r
-    return -1;\r
-}\r
-\r
-\r
-bool SerialWindows::WriteData(void *buffer, unsigned int nbChar)\r
-{\r
-    DWORD bytesSend;\r
-\r
-    //Try to write the buffer on the Serial port\r
-    if(!WriteFile(_hSerial, buffer, nbChar, &bytesSend, 0))\r
-    {\r
-        //In case it don't work get comm error and return false\r
-        ClearCommError(_hSerial, &_errors, &_status);\r
-\r
-        return false;\r
-    }\r
-    else\r
-       {\r
-        ClearCommError(_hSerial, &_errors, &_status);\r
-/*             if(!FlushFileBuffers(_hSerial))\r
-                       cout << "ERROR while flushing" << endl;*/\r
-/*             stringstream s;
-               s << bytesSend << " SENT" << endl;
-               OutputDebugString(s.str().c_str());*/
-        return true;\r
-       }\r
-}\r