<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>README_win32.txt</filename>
    </added>
    <added>
      <filename>gui/scrobui.dsp</filename>
    </added>
    <added>
      <filename>gui/scrobui.dsw</filename>
    </added>
    <added>
      <filename>loopdub.dsp</filename>
    </added>
    <added>
      <filename>loopdub.dsw</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -3,3 +3,7 @@
 
 Initial import into CVS.  Marked as version 0.1
 
+* May 15, 2005
+
+Windows version sort of works.  Still needs some thread priority bugs
+to be worked out.</diff>
      <filename>ChangeLog</filename>
    </modified>
    <modified>
      <diff>@@ -34,7 +34,6 @@ short Lowpass::Work(short sample)
 
 	// filter
 	float temp_y;
-	int   i;
 	float alpha, omega, sn, cs;
 	float a0, a1, a2, b0, b1, b2;
 	float coef[5];</diff>
      <filename>filter.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -5,8 +5,8 @@
 class Filter
 {
   public:
-	virtual void Initialize() {}
-	virtual short Work(short sample) {}
+	  virtual void Initialize() {}
+	  virtual short Work(short sample) { return 0; }
 };
 
 class Lowpass : public Filter</diff>
      <filename>filter.h</filename>
    </modified>
    <modified>
      <diff>@@ -510,37 +510,41 @@ void DrawingTools::FillRect(Rect r, int color)
 	if (r.IsValid())
 		SDL_FillRect(m_pSurface, &amp;sr, color);
 }
-
+
+#include &lt;assert.h&gt;
 bool DrawingTools::LoadCharacterData(char *filename)
-{
-	ifstream charfile(filename, ios::in | ios::binary);
-	if (!charfile.is_open())
+{
+	ifstream charfile(filename, ios::in | ios::binary);
+
+	if (!charfile.is_open())
 	{
 		fprintf(stderr, &quot;Couldn't open %s.\n&quot;, filename);
 		return false;
-	}
-
+	}
+
 	for (int i=0; i&lt;95; i++)
 	{
-		charfile.read((char*)&amp;m_nCharOffsets[i], 2);
-		charfile.read((char*)&amp;m_nCharWidths[i], 1);
-	}
+		charfile.read((char*)&amp;m_nCharOffsets[i], 2);
+		charfile.read((char*)&amp;m_nCharWidths[i], 1);
+	}
 
 	short sx, sy;
-	charfile.read((char*)&amp;sx, 2);
-	charfile.read((char*)&amp;sy, 2);
-	m_nFontHeight = sy;
-
-	m_pCharacterData = new char[sx*sy];
-
-	charfile.read(m_pCharacterData, sx*sy);
-	if (charfile.fail() || charfile.bad())
+	charfile.read((char*)&amp;sx, 2);
+	charfile.read((char*)&amp;sy, 2);
+	m_nFontHeight = sy;
+
+	m_pCharacterData = new char[sx*sy];
+
+	if (!charfile.fail() &amp;&amp; !charfile.bad())
+		charfile.read(m_pCharacterData, sx*sy);
+
+	if (charfile.fail() || charfile.bad())
 	{
 		fprintf(stderr, &quot;Error reading character data.\n&quot;);
 		delete m_pCharacterData;
 		m_pCharacterData = NULL;
 		return false;
-	}
+	}
 
 	m_pCharacterSurface = SDL_CreateRGBSurfaceFrom(m_pCharacterData, sx, sy, 8, sx, 0, 0, 0, 0);
 	if (!m_pCharacterSurface)</diff>
      <filename>gui/scrobui.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 #ifndef _SCROBUI_H_
 #define _SCROBUI_H_
 
-#include &lt;SDL/SDL.h&gt;
+#include &lt;SDL.h&gt;
 
 //namespace ScrobUI {
 </diff>
      <filename>gui/scrobui.h</filename>
    </modified>
    <modified>
      <diff>@@ -6,12 +6,17 @@
 #include &quot;scrobui.h&quot;
 #include &lt;string.h&gt;
 #include &lt;ctype.h&gt;
-#include &lt;stdlib.h&gt;
-#include &lt;dirent.h&gt;
-#include &lt;sys/stat.h&gt;
-
-#ifdef WIN32
-#define snprintf _snprintf
+#include &lt;stdlib.h&gt;
+
+#ifdef WIN32
+  #include &lt;io.h&gt;
+  #define snprintf _snprintf
+  #define realpath(srcpath, destpath) _fullpath(destpath, srcpath, MAX_PATH)
+  #define DIR_SEPARATOR &quot;\\&quot;
+#else
+  #include &lt;dirent.h&gt;
+  #include &lt;sys/stat.h&gt;
+  #define DIR_SEPARATOR &quot;/&quot;
 #endif
 
 #ifndef min
@@ -344,7 +349,8 @@ bool Image::Create(Scrob *pParent, const Rect&amp; r, int width, int height, char* d
 	 if (m_nWidth &lt; 0) m_nWidth = 0;
 	 m_nHeight = height;
 	 if (m_nHeight &lt; 0) m_nHeight = 0;
-	 m_pData = data;
+	 m_pData = data;
+	 return true;
 }
 
 void Image::Draw()
@@ -400,7 +406,8 @@ bool Button::Create(Scrob *pParent, const Rect&amp; r, char *strText, int color, int
   Label::Create(pParent, r, strText, color, bkcolor);
   m_nCommand = command;
   m_nCommandValue = command_value;
-  m_bToggle = bToggle;
+  m_bToggle = bToggle;
+
   return true;
 }
 
@@ -640,12 +647,14 @@ FileBrowser::FileBrowser() : Scrob()
 	m_nRows = 0;
 	m_nColumns = 0;
 	m_bShowDir = true;
-	m_pBox = NULL;
+	m_pBox = NULL;
+	m_pFolder = NULL;
 	m_nItemWidth = 0;
 	m_nCommand = 0;
 	m_bExt = false;
 	m_bBase = false;
 	m_nNames = 0;
+	m_nDrawFileOffset = 0;
 }
 
 FileBrowser::FileBrowser(Scrob *pParent, const Rect&amp; r, char *strDir, int command, bool showDir)
@@ -654,10 +663,12 @@ FileBrowser::FileBrowser(Scrob *pParent, const Rect&amp; r, char *strDir, int comman
 	m_nRows = 0;
 	m_nColumns = 0;
 	m_pBox = NULL;
+	m_pFolder = NULL;
 	m_nItemWidth = 0;
 	m_bExt = false;
 	m_bBase = false;
 	m_nNames = 0;
+	m_nDrawFileOffset = 0;
 	Create(pParent, r, strDir, command, showDir);
 }
 
@@ -711,7 +722,7 @@ void FileBrowser::Draw()
 								  c*m_nItemWidth+m_nItemWidth+x-2, r*h+1+h));
 			  dt.TextOut(Point(c*m_nItemWidth+x,r*h+1),
 						 m_names[i],
-						 (m_types[i] &amp; DT_DIR) ? 2 : 3);
+						 m_isdir[i] ? 2 : 3);
 		 }
 	dt.SetClipRect();
 
@@ -747,11 +758,60 @@ void FileBrowser::Draw()
 		 dt.PutPixel(Point(x+2, y-2), 2);
 		 dt.PutPixel(Point(x+2, y+2), 2);
 	}
-}
-
+}
+
 void FileBrowser::SetDirectory(char *strDir)
-{	
-	 char realdir[1024];
+{
+#ifdef WIN32
+
+	char realdir[MAX_PATH];
+	if (!_fullpath(realdir, strDir, MAX_PATH))
+		return;
+	strncpy(m_strDir, realdir, MAX_PATH);
+	if (m_pFolder)
+		m_pFolder-&gt;SetText(m_strDir);
+
+	// Are we in base directory?
+	bool bBaseDir = m_bBase ? strcmp(m_strDir, m_strBase)==0 : false;
+
+	// Append search item
+	strcat(realdir, DIR_SEPARATOR);
+	strcat(realdir, &quot;*&quot;);
+
+	// Read directory
+	_finddata_t fd;
+	long lSearch = _findfirst(realdir, &amp;fd);
+	if (lSearch==-1)
+		return;
+
+	m_nNames=0;
+	char pathstr[MAX_PATH];
+
+	int extlen=0;
+	if (m_bExt)
+		extlen = strlen(m_strExt);
+
+	do {
+		if (m_bExt
+			&amp;&amp; stricmp(fd.name+strlen(fd.name)-extlen, m_strExt)!=0
+			&amp;&amp; !(fd.attrib &amp; _A_SUBDIR))
+			continue;
+
+		if (strcmp(fd.name, &quot;.&quot;)==0) continue;
+		if (bBaseDir &amp;&amp; strcmp(fd.name, &quot;..&quot;)==0) continue;
+
+		strcpy(pathstr, m_strDir);
+		strcat(pathstr, DIR_SEPARATOR);
+		strcat(pathstr, fd.name);
+		m_isdir[m_nNames] = (fd.attrib &amp; _A_SUBDIR)!=0;
+		strcpy(m_names[m_nNames++], fd.name);
+	} while ((_findnext(lSearch, &amp;fd)==0) &amp;&amp; (m_nNames &lt; MAX_FB_NAMES));
+
+	_findclose(lSearch);
+
+#else
+
+	 char realdir[MAX_PATH];
 	 if (!realpath(strDir, realdir))
 		  return;
 	 strncpy(m_strDir, realdir, MAX_PATH);
@@ -765,7 +825,7 @@ void FileBrowser::SetDirectory(char *strDir)
 	DIR *dir;
 	dir = opendir(m_strDir);
 	m_nNames=0;
-	char pathstr[1024];
+	char pathstr[MAX_PATH];
 	struct stat st;
 	if (dir) {
 		 struct dirent *de;
@@ -776,7 +836,7 @@ void FileBrowser::SetDirectory(char *strDir)
 		 while ((de = readdir(dir)) &amp;&amp; m_nNames&lt;MAX_FB_NAMES)
 		 {
 			  strcpy(pathstr, m_strDir);
-			  strcat(pathstr, &quot;/&quot;);
+			  strcat(pathstr, DIR_SEPARATOR);
 			  strcat(pathstr, de-&gt;d_name);
 
 			  if ((stat(pathstr, &amp;st)==0) &amp;&amp; S_ISDIR(st.st_mode))
@@ -786,12 +846,14 @@ void FileBrowser::SetDirectory(char *strDir)
 			  {
 				   if (strcmp(de-&gt;d_name, &quot;.&quot;)==0) continue;
 				   if (bBaseDir &amp;&amp; strcmp(de-&gt;d_name, &quot;..&quot;)==0) continue;
-				   m_types[m_nNames] = de-&gt;d_type;
+				   m_isdir[m_nNames] = (de-&gt;d_type &amp; DT_DIR)!=0;
 				   strcpy(m_names[m_nNames++], de-&gt;d_name);
 			  }
 		 }
 		 closedir(dir);
-	}
+	}
+
+#endif
 
 	m_nDrawFileOffset = 0;
 
@@ -811,7 +873,7 @@ void FileBrowser::SetExtension(char *strExt)
 		  m_bExt = false;
 	 }
 }
-
+
 void FileBrowser::SetBase(char *strBase)
 {
 	 if (strBase) {
@@ -846,18 +908,18 @@ void FileBrowser::OnMouseUp(Point mouse)
 	 int n = c*m_nRows + r + m_nDrawFileOffset;
 	 if (n &lt; m_nNames)
 	 {
-		  if (m_types[n] &amp; DT_DIR) {
-			   char path[MAX_PATH], real[MAX_PATH];
+		  if (m_isdir[n]) {
+			   char path[MAX_PATH];
 			   strcpy(path, m_strDir);
 			   if (path[strlen(path)-1]!='/')
-					strcat(path, &quot;/&quot;);
+					strcat(path, DIR_SEPARATOR);
 			   strcat(path, m_names[n]);
 			   SetDirectory(path);
 		  }
 		  else {
 			   strcpy(m_strFile, m_strDir);
-			   if (m_strFile[strlen(m_strFile)-1]!='/')
-					strcat(m_strFile, &quot;/&quot;);
+			   if (m_strFile[strlen(m_strFile)-1]!=DIR_SEPARATOR[0])
+					strcat(m_strFile, DIR_SEPARATOR);
 
 			   strcat(m_strFile, m_names[n]);
 			   gui.SetCommand(m_nCommand, (void*)m_strFile);</diff>
      <filename>gui/toolkit.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -11,10 +11,12 @@
 
 #define MAX_FB_NAMES 50
 
-#ifdef WIN32
+#ifndef MAX_PATH
+#ifdef WIN32
 #define MAX_PATH _MAX_PATH
 #else
 #define MAX_PATH PATH_MAX
+#endif
 #endif
 
 
@@ -199,7 +201,7 @@ protected:
 	bool m_bExt;
 	char m_strBase[MAX_PATH];
 	bool m_bBase;
-	char m_types[MAX_FB_NAMES];
+	bool m_isdir[MAX_FB_NAMES];
 	char m_names[MAX_FB_NAMES][256];
 	int m_nNames;
 </diff>
      <filename>gui/toolkit.h</filename>
    </modified>
    <modified>
      <diff>@@ -2,9 +2,13 @@
 #define _LOOPDUB_CPP_
 #include &lt;stdio.h&gt;
 #include &lt;string.h&gt;
-#include &lt;unistd.h&gt;
 #include &quot;loopdub.h&quot;
 #include &quot;ld_logo.h&quot;
+
+#ifdef WIN32
+#else
+  #include &lt;unistd.h&gt;
+#endif
 
 /* One global LoopDub object */
 LoopDub app;
@@ -27,23 +31,20 @@ LoopDub::LoopDub()
 	 m_nKeysChannel = -1;
 	 for (int i=0; i&lt;MAX_KEYS; i++)
 		  m_Keys[i].on = false;
-
-	 if (pthread_mutex_init(&amp;mutex, NULL)!=0) {
-		  printf(&quot;Couldn't init mutex?!\n&quot;);
-		  exit(0);
-	 }
+
+	 CREATEMUTEX(mutex);
 }
 
 LoopDub::~LoopDub()
 {
-	 pthread_mutex_destroy(&amp;mutex);
+	DESTROYMUTEX(mutex);
 }
 
 void LoopDub::FillBuffers(void *param)
 {
 	LoopDub&amp; app = *(LoopDub*)param;
 
-	pthread_mutex_lock(&amp;app.mutex);
+	LOCKMUTEX(app.mutex);
 
 	short* pBufferL = app.m_Player.LeftBuffer();
 	short* pBufferR = app.m_Player.RightBuffer();
@@ -102,22 +103,24 @@ void LoopDub::FillBuffers(void *param)
 		 app.updated = false;
 	}
 
-	pthread_mutex_unlock(&amp;app.mutex);
+	UNLOCKMUTEX(app.mutex);
 }
 
-void* loadSampleThread(void* pApp)
-{
+THREADFUNC loadSampleThread(void* pApp)
+{
+	if (!pApp) return NULL;
+
 	 LoopDub &amp;app = *(LoopDub*)pApp;
 
 	 Sample *pSample = new Sample();
 	 if (pSample &amp;&amp; pSample-&gt;LoadFromFile(app.m_strLoadingSample))
 	 {
-		  pthread_mutex_lock(&amp;app.mutex);
+		  LOCKMUTEX(app.mutex);
 		  if (app.m_nLength==0) app.m_nLength = pSample-&gt;m_nSamples;
 		  Sample *pOldSample = app.m_pLoopOb[app.m_nLoadingSampleFor]-&gt;SetSample(pSample);
 		  if (pOldSample)
 			   delete pOldSample;
-		  pthread_mutex_unlock(&amp;app.mutex);
+		  UNLOCKMUTEX(app.mutex);
 	 }
 
 	 return NULL;
@@ -213,6 +216,8 @@ int LoopDub::Run()
 		printf(&quot;Couldn't initialize player.\n&quot;);
 		return 1;
 	}
+
+	m_Player.Play();
 
 	SDL_TimerID timerID=0;
 	SDL_Event *pEvent;
@@ -221,7 +226,7 @@ int LoopDub::Run()
 	{
 		gui.WaitEvent();
 
-		pthread_mutex_lock(&amp;mutex);
+		LOCKMUTEX(mutex);
 
 		if ((pEvent=gui.GetEvent())-&gt;type == SDL_KEYDOWN
 			&amp;&amp; pEvent-&gt;key.keysym.sym == SDLK_RETURN
@@ -294,9 +299,9 @@ int LoopDub::Run()
 
 					   m_nLoadingSampleFor = s;
 					   strcpy(m_strLoadingSample, (char*)value);
-
-					   pthread_t thread;
-					   pthread_create(&amp;thread, NULL, loadSampleThread, (void*)this);
+
+					   HTHREAD thread;
+					   CREATETHREAD(thread, loadSampleThread, &amp;app);
 				  }
 				  else if (cmd&gt;=CMD_CLOSE &amp;&amp; cmd&lt;(CMD_CLOSE+N_LOOPS))
 				  {
@@ -338,13 +343,13 @@ int LoopDub::Run()
 
 			 app.updated = true;
 
-			 pthread_mutex_unlock(&amp;mutex);
+			 UNLOCKMUTEX(mutex);
 			 m_Midi.CheckMsg();
 		}
 	}
 
 	app.updated = true;
-	pthread_mutex_unlock(&amp;mutex);
+	UNLOCKMUTEX(mutex);
 	m_Player.Stop();
 
 	return 0;
@@ -352,7 +357,7 @@ int LoopDub::Run()
 
 int main(int argc, char* argv[])
 {
-	 if ((argc &gt; 1) &amp;&amp; argv[1]) {
+	 if ((argc &gt; 1) &amp;&amp; argv[1]) {
 		  if (strcmp(argv[1], &quot;-v&quot;)==0) {
 			   printf(&quot;LoopDub &quot; APP_VERSION &quot;\n&quot;);
 			   exit(0);</diff>
      <filename>loopdub.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -1,11 +1,12 @@
 #ifndef _LOOPDUB_H_
 #define _LOOPDUB_H_
-
-#include &lt;pthread.h&gt;
-#include &lt;SDL/SDL.h&gt;
-#include &quot;scrobui.h&quot;
-#include &quot;portmidi/pm_common/portmidi.h&quot;
-//using namespace ScrobUI;
+
+#include &quot;platform.h&quot;
+#include &lt;SDL.h&gt;
+#include &quot;gui/scrobui.h&quot;
+#include &quot;portmidi/pm_common/portmidi.h&quot;
+//using namespace ScrobUI;
+
 
 // Global definitions
 #define N_LOOPS   8
@@ -82,7 +83,7 @@ public:
 	Slider *m_pVolumeSlider;
 	Button *m_pAutoCueButton;
 
-	pthread_mutex_t mutex;
+	HMUTEX mutex;
 
 	// loading
 	int m_nLoadingSampleFor;</diff>
      <filename>loopdub.h</filename>
    </modified>
    <modified>
      <diff>@@ -189,8 +189,9 @@ bool LoopOb::Create(Scrob *pParent, const Rect&amp; r, int number, Sample *pSample)
 	AddChild(m_pWaveOb);
 
 	m_pWaveOb-&gt;SetColor(2);
-
-	for (int i=0; i&lt;2; i++) {
+
+	int i;
+	for (i=0; i&lt;2; i++) {
 		 m_pIndicator[i] = new IndicatorOb;
 		 if (!m_pIndicator[i]-&gt;Create(this, Rect(LOOP_X, 2, 61, r.Height()-3)))
 			  return false;
@@ -303,7 +304,7 @@ bool LoopOb::Create(Scrob *pParent, const Rect&amp; r, int number, Sample *pSample)
 
 	m_filterbank[0] = &amp;lowpass;
 	m_filterbank[1] = &amp;delay;
-	for (int i=0; i&lt;N_FILTERS; i++)
+	for (i=0; i&lt;N_FILTERS; i++)
 		 m_filterbank[i]-&gt;Initialize();
 
 	return true;</diff>
      <filename>loopob.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@
 #ifndef _LOOPOB_H_
 #define _LOOPOB_H_
 
-#include &quot;scrobui.h&quot;
+#include &quot;gui/scrobui.h&quot;
 //using namespace ScrobUI;
 #include &quot;sample.h&quot;
 #include &quot;filter.h&quot;</diff>
      <filename>loopob.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,13 +1,13 @@
 // Sample.cpp: implementation of the Sample class.
 //
 //////////////////////////////////////////////////////////////////////
-
+
+#include &quot;platform.h&quot;
 #include &quot;sample.h&quot;
 #include &lt;math.h&gt;
 #include &lt;string.h&gt;
-#include &lt;stdio.h&gt;
-#include &lt;unistd.h&gt;
-
+#include &lt;stdio.h&gt;
+
 Sample::Sample()
 {
 	m_pData = 0;
@@ -176,8 +176,8 @@ bool Sample::LoadFromFile(char *filename)
 				while (size-- &gt; 0)
 					fread(&amp;dw, 1, 1, f);
 			}
-
-			usleep(10);
+
+			USLEEP(10);
 
 			fread(&amp;dw, 4, 1, f);
 		}</diff>
      <filename>sample.cpp</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>468b69c75db072c72b6697ffcf7d9e8711b54ec3</id>
    </parent>
  </parents>
  <author>
    <name>radarsat1</name>
    <email>radarsat1</email>
  </author>
  <url>http://github.com/radarsat1/LoopDub/commit/0f4c99f0cbab63acaf3ec005ce2ee06319eb897f</url>
  <id>0f4c99f0cbab63acaf3ec005ce2ee06319eb897f</id>
  <committed-date>2005-05-15T14:58:52-07:00</committed-date>
  <authored-date>2005-05-15T14:58:52-07:00</authored-date>
  <message>Windows version sort of works, still has some thread priority bugs
to be worked out.
Need to ensure VC++ documentation is good.</message>
  <tree>7f7da87000fa15650d94db27c6574c12924c4e22</tree>
  <committer>
    <name>radarsat1</name>
    <email>radarsat1</email>
  </committer>
</commit>
