--- pyepl-1.1.0.orig/changelog.txt
+++ pyepl-1.1.0/changelog.txt
@@ -1,4 +1,9 @@
+Version ?.?.?
+-------------
 
+ - Fixed a sound bug that cleared the recording buffer when you played
+   a sound while trying to record.
+ - Added ability to flush the recording buffer.
 
 
 Version 1.1.0
--- pyepl-1.1.0.orig/code/sound.py
+++ pyepl-1.1.0/code/sound.py
@@ -532,6 +532,7 @@
         Clean up the sound system.
         """
 	self.playStop()
+        self.stopRecording()
 	self.eplsound.stopstream()
         
     def play(self, soundClip, t = None, ampFactor=1.0, doDelay=True):
@@ -630,7 +631,7 @@
 	    # see if stop the time
 	    if self.startInd < self.endInd:
 
-		# determin how much to append
+		# determine how much to append
 		actualInd = self.startInd + self.bytes_per_append
 
 		# make sure it's not beyond the end
@@ -639,7 +640,8 @@
 		    actualInd = self.endInd
 		
 		# append the sound
-		appended = self.eplsound.append(s[self.startInd:actualInd], len(s[self.startInd:actualInd])/self.eplsound.FORMAT_SIZE, 0, ampFactor)
+		appended = self.eplsound.append(s[self.startInd:actualInd],
+                                                len(s[self.startInd:actualInd])/self.eplsound.FORMAT_SIZE, 0, ampFactor)
 
 		self.last_play = currentTime
 		
@@ -653,26 +655,16 @@
 		    self.playStop()
 
     def playLoopStop(self, doUnload=True):
-	if self.playing:
-	    self.playing = False
-	    removePollCallback(self.__playLoopCallback__)           
-        
-        # clear the sound buffer to stop playing
-	self.eplsound.clear()
-
-	if isinstance(self.currentClip, FileAudioClip) and self.currentClip.isLoaded() and doUnload:
-	    self.currentClip.unload()
-	    
-	return self.eplsound.getSamplesPlayed()
-
+        self.playStop(doUnload)
 
     def playStop(self, doUnload=True):
 	if self.playing:
 	    self.playing = False
 	    removePollCallback(self.__playCallback__)           
+	    removePollCallback(self.__playLoopCallback__)           
         
         # clear the sound buffer to stop playing
-	self.eplsound.clear()
+	self.eplsound.clearPlayBuffer()
 
 	if isinstance(self.currentClip, FileAudioClip) and self.currentClip.isLoaded() and doUnload:
 	    self.currentClip.unload()
@@ -849,6 +841,20 @@
             
             return (self.recClip,timeInterval)
 
+    def flush(self):
+        """
+        Flush the recording buffer.
+        """
+        currentTime = timing.now()
+        newstuff = self.getBuffData()
+
+        # Update the last time
+        self.last_rec = currentTime
+
+        if len(newstuff) > 0:
+            # append the data to the clip
+            self.recClip.append(newstuff, self.eplsound.getRecChans())        
+        
 
     def __recCallback__(self):
         """
--- pyepl-1.1.0.orig/code/display.py
+++ pyepl-1.1.0/code/display.py
@@ -62,7 +62,9 @@
         self.loadRequireCount -= 1
         if self.loadRequireCount < 0:
             self.loadRequireCount = 0
-        if self.loadRequireCount == 0 and self.isLoaded():
+        if self.loadRequireCount == 0 and \
+                self.isLoaded() and \
+                (hasattr(self,'filename') and not self.filename is None):
             self.unload()
     def show(self, x, y):  # to be overridden
         """
@@ -915,7 +917,7 @@
         return result
 
 # create the initial font defaults...
-defaultFont = Font(os.path.join(pyepldir, "resources", "vera.ttf"))
+defaultFont = Font("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf")
 defaultFontSize = 0.0625
 defaultFontColor = Color("white")
 
--- pyepl-1.1.0.orig/code/hardware/sound/RtAudio.cpp
+++ pyepl-1.1.0/code/hardware/sound/RtAudio.cpp
@@ -38,7 +38,7 @@
 */
 /************************************************************************/
 
-// RtAudio: Version 4.0.5
+// RtAudio: Version 4.0.6
 
 #include "RtAudio.h"
 #include <iostream>
@@ -403,7 +403,9 @@
 // implementation.
 struct CoreHandle {
   AudioDeviceID id[2];    // device ids
+#if defined( MAC_OS_X_VERSION_10_5 ) && ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 )
   AudioDeviceIOProcID procId[2];
+#endif
   UInt32 iStream[2];      // device stream index (or first if using multiple)
   UInt32 nStreams[2];     // number of streams to use
   bool xrun[2];
@@ -539,7 +541,7 @@
 
   // Get the device name.
   info.name.erase();
-  char	name[256];
+  char  name[256];
   dataSize = 256;
   result = AudioDeviceGetProperty( id, 0, false,
                                    kAudioDevicePropertyDeviceManufacturer,
@@ -567,7 +569,7 @@
   info.name.append( (const char *)name, strlen(name) );
 
   // Get the output stream "configuration".
-  AudioBufferList	*bufferList = nil;
+  AudioBufferList   *bufferList = nil;
   result = AudioDeviceGetPropertyInfo( id, 0, false,
                                        kAudioDevicePropertyStreamConfiguration,
                                        &dataSize, NULL );
@@ -790,7 +792,7 @@
   }
 
   // Get the stream "configuration".
-  AudioBufferList	*bufferList;
+  AudioBufferList   *bufferList;
   result = AudioDeviceGetPropertyInfo( id, 0, isInput,
                                        kAudioDevicePropertyStreamConfiguration,
                                        &dataSize, NULL );
@@ -884,7 +886,7 @@
   free( bufferList );
 
   // Determine the buffer size.
-  AudioValueRange	bufferRange;
+  AudioValueRange   bufferRange;
   dataSize = sizeof( AudioValueRange );
   result = AudioDeviceGetProperty( id, 0, isInput,
                                    kAudioDevicePropertyBufferFrameSizeRange,
@@ -940,7 +942,7 @@
 
   // Now set the stream format.  Also, check the physical format of the
   // device and change that if necessary.
-  AudioStreamBasicDescription	description;
+  AudioStreamBasicDescription   description;
   dataSize = sizeof( AudioStreamBasicDescription );
 
   bool updateFormat;
@@ -991,20 +993,31 @@
       return FAILURE;
     }
 
+// Snow Leopard / Leopard Fix =================================================                                     
+
+/**/description.mSampleRate = sampleRate;
+/**/result = AudioDeviceSetProperty( streamIDs[firstStream+i], NULL, 0, isInput,
+/**/                                 kAudioDevicePropertyStreamFormat,
+/**/                                 dataSize, &description );
+      
     if ( description.mFormatID != kAudioFormatLinearPCM || description.mBitsPerChannel < 24 ) {
       description.mFormatID = kAudioFormatLinearPCM;
-      AudioStreamBasicDescription	testDescription = description;
+      AudioStreamBasicDescription   testDescription = description;
       unsigned long formatFlags;
 
       // We'll try higher bit rates first and then work our way down.
       testDescription.mBitsPerChannel = 32;
-      formatFlags = description.mFormatFlags | kLinearPCMFormatFlagIsFloat & ~kLinearPCMFormatFlagIsSignedInteger;
+/**/  testDescription.mBytesPerFrame =  testDescription.mBitsPerChannel/8 * testDescription.mChannelsPerFrame;
+/**/  testDescription.mBytesPerPacket = testDescription.mBytesPerFrame * testDescription.mFramesPerPacket;
+      formatFlags = (description.mFormatFlags | kLinearPCMFormatFlagIsFloat) & ~kLinearPCMFormatFlagIsSignedInteger;
       testDescription.mFormatFlags = formatFlags;
       result = AudioStreamSetProperty( streamIDs[firstStream+i], NULL, 0, kAudioStreamPropertyPhysicalFormat, dataSize, &testDescription );
       if ( result == noErr ) continue;
 
       testDescription = description;
       testDescription.mBitsPerChannel = 32;
+/**/  testDescription.mBytesPerFrame =  testDescription.mBitsPerChannel/8 * testDescription.mChannelsPerFrame;
+/**/  testDescription.mBytesPerPacket = testDescription.mBytesPerFrame * testDescription.mFramesPerPacket;
       formatFlags = (description.mFormatFlags | kLinearPCMFormatFlagIsSignedInteger) & ~kLinearPCMFormatFlagIsFloat;
       testDescription.mFormatFlags = formatFlags;
       result = AudioStreamSetProperty( streamIDs[firstStream+i], NULL, 0, kAudioStreamPropertyPhysicalFormat, dataSize, &testDescription );
@@ -1012,24 +1025,33 @@
 
       testDescription = description;
       testDescription.mBitsPerChannel = 24;
+/**/  testDescription.mBytesPerFrame =  testDescription.mBitsPerChannel/8 * testDescription.mChannelsPerFrame;
+/**/  testDescription.mBytesPerPacket = testDescription.mBytesPerFrame * testDescription.mFramesPerPacket;
       testDescription.mFormatFlags = formatFlags;
       result = AudioStreamSetProperty( streamIDs[firstStream+i], NULL, 0, kAudioStreamPropertyPhysicalFormat, dataSize, &testDescription );
       if ( result == noErr ) continue;
 
       testDescription = description;
       testDescription.mBitsPerChannel = 16;
+/**/  testDescription.mBytesPerFrame =  testDescription.mBitsPerChannel/8 * testDescription.mChannelsPerFrame;
+/**/  testDescription.mBytesPerPacket = testDescription.mBytesPerFrame * testDescription.mFramesPerPacket;
       testDescription.mFormatFlags = formatFlags;
       result = AudioStreamSetProperty( streamIDs[firstStream+i], NULL, 0, kAudioStreamPropertyPhysicalFormat, dataSize, &testDescription );
       if ( result == noErr ) continue;
 
       testDescription = description;
       testDescription.mBitsPerChannel = 8;
+/**/  testDescription.mBytesPerFrame =  testDescription.mBitsPerChannel/8 * testDescription.mChannelsPerFrame;
+/**/  testDescription.mBytesPerPacket = testDescription.mBytesPerFrame * testDescription.mFramesPerPacket;
       testDescription.mFormatFlags = formatFlags;
       result = AudioStreamSetProperty( streamIDs[firstStream+i], NULL, 0, kAudioStreamPropertyPhysicalFormat, dataSize, &testDescription );
       if ( result != noErr ) {
         errorStream_ << "RtApiCore::probeDeviceOpen: system error (" << getErrorCode( result ) << ") setting physical data format for device (" << device << ").";
         errorText_ = errorStream_.str();
         return FAILURE;
+
+// End Snow Leopard / Leopard Fix =============================================
+
       }
     }
   }
@@ -5646,7 +5668,7 @@
   }
 
   // Set the buffer number, which in ALSA is referred to as the "period".
-  int totalSize, dir;
+  int totalSize, dir = 0;
   unsigned int periods = 0;
   if ( options ) periods = options->numberOfBuffers;
   totalSize = *bufferSize * periods;
--- pyepl-1.1.0.orig/code/hardware/sound/eplSound.cpp
+++ pyepl-1.1.0/code/hardware/sound/eplSound.cpp
@@ -19,6 +19,9 @@
 		   unsigned int sampRate, unsigned int bufSize)
 {
   // get audio instance
+  RtAudio audio;
+  playAudio = NULL;
+  recAudio = NULL;
 
   // let's see warnings
   audio.showWarnings( true );
@@ -84,37 +87,53 @@
 
   try {
     // open the proper stream
-    if ((playChans>0) && (recChans>0))
+    if ((playChans>0) && (recChans>0) && (iParams.deviceId == oParams.deviceId))
     {
+      // it's duplex
+      isDuplex = 1;
+      
       // open both
-      audio.openStream( &oParams, &iParams, FORMAT, sampleRate, 
-			&bufferSize, &inout, (void *)data );
+      playAudio = new RtAudio();
+      playAudio->showWarnings( true );
+      playAudio->openStream( &oParams, &iParams, FORMAT, sampleRate, 
+			    &bufferSize, &inout, (void *)data );
+      recAudio = playAudio;
     }
-    else if (playChans>0)
+    else 
+    {
+      // not full duplex
+      isDuplex = 0;
+
+      if (playChans>0)
+      {
+	// open output
+	playAudio = new RtAudio();
+	playAudio->showWarnings( true );
+	playAudio->openStream( &oParams, NULL, FORMAT, sampleRate, 
+			       &bufferSize, &inout, (void *)data );
+      }
+      if (recChans>0)
+      {
+	// open input
+	recAudio = new RtAudio();
+	recAudio->showWarnings( true );
+	recAudio->openStream( NULL, &iParams, FORMAT, sampleRate, 
+			      &bufferSize, &inout, (void *)data );	
+      }
+    }
+
+    if (playChans==0)
     {
-      // open only output
-      audio.openStream( &oParams, NULL, FORMAT, sampleRate, 
-			&bufferSize, &inout, (void *)data );
       // No input chans discovered
       cerr << "No default input device with correct channel info was found!" << endl;
       cerr << "You will only be able to record sound." << endl;
     }
-    else if (recChans>0)
+    if (recChans==0)
     {
-      // open only input
-      audio.openStream( NULL, &iParams, FORMAT, sampleRate, 
-			&bufferSize, &inout, (void *)data );
-
       // No output chans discovered
       cerr << "No default output device with correct channel info was found!" << endl;
       cerr << "You will not be able to play sound." << endl;
     }
-    else
-    {
-      cerr << "No default i/o device with correct channel info was found!" << endl;
-      cerr << "You will not be able to play or record sound." << endl;
-      //exit( EXIT_FAILURE );
-    }
   }
   catch ( RtError& e ) {
     e.printMessage();
@@ -127,10 +146,27 @@
 
 eplSound::~eplSound()
 {
-  if (audio.isStreamOpen() > 0)
+  // stop streaming
+  stopstream(1);
+
+  // close the play stream
+  if (playAudio != NULL)
   {
-    stopstream();
-    audio.closeStream();
+    if (playAudio->isStreamOpen() > 0)
+      playAudio->closeStream();
+
+    // clean it up
+    delete playAudio;
+  }
+
+  // see if should clean up record stream
+  if ((!isDuplex) && (recAudio != NULL))
+  {
+    if (recAudio->isStreamOpen() > 0)
+      recAudio->closeStream();
+
+    // clean it up
+    delete recAudio;
   }
   
   delete data;
@@ -143,6 +179,18 @@
   return;
 }
 
+void eplSound::clearPlayBuffer()
+{
+  data->playBuf->clear();
+  return;
+}
+
+void eplSound::clearRecBuffer()
+{
+  data->recBuf->clear();
+  return;
+}
+
 int eplSound::recstart()
 {
 
@@ -171,31 +219,71 @@
   //if (!(audio.isStreamOpen()) && (streaming == 0))
   if (streaming == 0)
   {
-    try {
-      audio.startStream();
+    // start playing
+    if (playAudio != NULL)
+    {
+      try {
+	playAudio->startStream();
+      }
+      catch (RtError &error) {
+	error.printMessage();
+	exit(EXIT_FAILURE);
+      }
     }
-    catch (RtError &error) {
-      error.printMessage();
-      exit(EXIT_FAILURE);
+
+    if ((recAudio != NULL) && (recAudio != playAudio))
+    {
+      try {
+	recAudio->startStream();
+      }
+      catch (RtError &error) {
+	error.printMessage();
+	exit(EXIT_FAILURE);
+      }
     }
+
+    // say we are streaming
     streaming = 1;
   }
 
   return 0; 
 }
 
-int eplSound::stopstream()
+int eplSound::stopstream(int abort)
 {
   //if (audio.isStreamOpen() && streaming == 1))
   if (streaming == 1)
   {
-    try {
-      audio.stopStream();
+    // stop playing
+    if (playAudio != NULL)
+    {
+      try {
+	if (abort)
+	  playAudio->abortStream();
+	else
+	  playAudio->stopStream();
+      }
+      catch (RtError &error) {
+	error.printMessage();
+	exit(EXIT_FAILURE);
+      }
     }
-    catch (RtError &error) {
-      error.printMessage();
-      exit(EXIT_FAILURE);
+
+    // stop playing
+    if ((recAudio != NULL) && (recAudio != playAudio))
+    {
+      try {
+	if (abort)
+	  recAudio->abortStream();
+	else
+	  recAudio->stopStream();
+      }
+      catch (RtError &error) {
+	error.printMessage();
+	exit(EXIT_FAILURE);
+      }
     }
+
     streaming = 0;
     data->recording = 0;
   }
@@ -256,11 +344,31 @@
   return sampleRate;
 }
 
+unsigned int eplSound::getPlayStreamSampleRate()
+{
+  return playAudio->getStreamSampleRate();
+}
+
+unsigned int eplSound::getRecStreamSampleRate()
+{
+  return recAudio->getStreamSampleRate();
+}
+
 long eplSound::getBufferUsed()
 {
   return data->playBuf->getUsed();
 }
 
+long eplSound::getPlayStreamLatency()
+{
+  return playAudio->getStreamLatency();
+}
+
+long eplSound::getRecStreamLatency()
+{
+  return recAudio->getStreamLatency();
+}
+
 int inout( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
            double streamTime, RtAudioStreamStatus status, void *data )
 {
@@ -297,7 +405,7 @@
 	     sizeof(MY_TYPE)*((nBufferFrames*mydata->playChans)-written));
     }
   }
-  
+
   return 0;
 }
 
--- pyepl-1.1.0.orig/code/hardware/sound/RtAudio.h
+++ pyepl-1.1.0/code/hardware/sound/RtAudio.h
@@ -42,7 +42,7 @@
   \file RtAudio.h
  */
 
-// RtAudio: Version 4.0.5
+// RtAudio: Version 4.0.6
 
 #ifndef __RTAUDIO_H
 #define __RTAUDIO_H
--- pyepl-1.1.0.orig/code/hardware/sound/eplSound.h
+++ pyepl-1.1.0/code/hardware/sound/eplSound.h
@@ -49,17 +49,23 @@
   long append(MY_TYPE *newdata, long length, int overwrite, float ampFactor);
   long consume(MY_TYPE *newdata, long length);
   void clear();
+  void clearPlayBuffer();
+  void clearRecBuffer();
   int recstart();
   int recstop();
   int startstream();
-  int stopstream();
+  int stopstream(int abort=0);
   int getBufferSize();
   long getSamplesPlayed();
   void resetSamplesPlayed();
   int getRecChans();
   int getPlayChans();
   int getSampleRate();
+  unsigned int getPlayStreamSampleRate();
+  unsigned int getRecStreamSampleRate();
   long getBufferUsed();
+  long getPlayStreamLatency();
+  long getRecStreamLatency();
   static const int SCALE=32767;  
   static const unsigned int SAMPLE_RATE=44100;
   static const int SAMPLE_SILENCE=0;
@@ -71,10 +77,10 @@
   static const long REC_BUF_LEN=60;
   static const int NUM_CHANNELS=2;
  private:
-  RtAudio audio;
-  //RtAudio *playaudio;
-  //RtAudio *recaudio;
-  //int isDuplex;
+  //RtAudio audio;
+  RtAudio *playAudio;
+  RtAudio *recAudio;
+  int isDuplex;
   unsigned int playChans;
   unsigned int recChans;
   //int rate;
--- pyepl-1.1.0.orig/code/hardware/vr/Makefile
+++ pyepl-1.1.0/code/hardware/vr/Makefile
@@ -18,11 +18,14 @@
 
 ifeq ($(PLATFORM), Linux)
 
+ODE_CFLAGS = $(shell ode-config --cflags)
+ODE_LDFLAGS = $(shell ode-config --libs)
+
 avatar.so: avatar.o
-	gcc -shared avatar.o -o avatar.so
+	gcc -shared avatar.o -o avatar.so $(ODE_LDFLAGS)
 
 avatar.o: avatar.c
-	gcc -c -fPIC -I$(INCLUDEPY) avatar.c
+	gcc -c -fPIC -I$(INCLUDEPY) $(ODE_CFLAGS) avatar.c
 
 avatar.c: avatar.pyx
 	pyrexc avatar.pyx
