<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,6 @@
   
   :$: BLOOPSAPHONE :$:
-  Copyright (c) 2008 why the lucky stiff
+  Copyright (c) 2009 why the lucky stiff
   Based on sfxr (c) 2007 Tomas Pettersson
     (Also released under the MIT license)
   </diff>
      <filename>COPYING</filename>
    </modified>
    <modified>
      <diff>@@ -94,6 +94,12 @@ bloops_clear(bloops *B)
 }
 
 void
+bloops_tempo(bloops *B, int tempo)
+{
+  B-&gt;tempo = tempo;
+}
+
+void
 bloops_track_at(bloops *B, bloopsatrack *track, int num)
 {
   B-&gt;tracks[num] = track;
@@ -111,6 +117,12 @@ bloops_play(bloops *B)
   B-&gt;play = BLOOPS_PLAY;
 }
 
+int
+bloops_is_done(bloops *B)
+{
+  return B-&gt;play == BLOOPS_STOP;
+}
+
 static void
 bloops_synth(bloops *B, int length, float* buffer)
 {
@@ -119,6 +131,7 @@ bloops_synth(bloops *B, int length, float* buffer)
   while (length--)
   {
     int samplecount = 0;
+    int moreframes = 0;
     float allsample = 0.0f;
 
     for (t = 0; t &lt; BLOOPS_MAX_TRACKS; t++)
@@ -146,8 +159,15 @@ bloops_synth(bloops *B, int length, float* buffer)
           }
           else if (A-&gt;frames &lt; frames)
             break;
-          frames += (int)(tempo2frames(A-&gt;tempo) * (4.0f / note-&gt;duration));
+          frames += (int)(tempo2frames(B-&gt;tempo) * (4.0f / note-&gt;duration));
         }
+
+        if (A-&gt;frames &lt;= frames)
+          moreframes++;
+      }
+      else
+      {
+        moreframes++;
       }
 
       A-&gt;frames++;
@@ -291,6 +311,8 @@ bloops_synth(bloops *B, int length, float* buffer)
       allsample += ssample;
     }
 
+    if (moreframes == 0)
+      B-&gt;play = BLOOPS_STOP;
     *buffer++ = allsample;
   }
 }
@@ -313,6 +335,19 @@ static int bloops_port_callback(const void *inputBuffer, void *outputBuffer,
 }
 
 bloopsaphone *
+bloops_square()
+{
+  bloopsaphone *P = (bloopsaphone *)calloc(sizeof(bloopsaphone), 1);
+  P-&gt;type = BLOOPS_SQUARE;
+  P-&gt;volume = 0.5f;
+  P-&gt;sustain = 0.3f;
+  P-&gt;decay = 0.4f;
+  P-&gt;freq = 0.3f;
+  P-&gt;lpf = 1.0f;
+  return P;
+}
+
+bloopsaphone *
 bloops_load(char* filename)
 {
   bloopsaphone *P = NULL;
@@ -368,7 +403,8 @@ bloops *
 bloops_new()
 {
   bloops *B = (bloops *)malloc(sizeof(bloops));
-  B-&gt;volume = 0.20f;
+  B-&gt;volume = 0.10f;
+  B-&gt;tempo = 120;
   B-&gt;play = BLOOPS_STOP;
   bloops_clear(B);
 
@@ -394,3 +430,11 @@ bloops_destroy(bloops *B)
   if (!--bloops_open)
     Pa_Terminate();
 }
+
+void
+bloops_track_destroy(bloopsatrack *track)
+{
+  if (track-&gt;notes != NULL)
+    free(track-&gt;notes);
+  free(track);
+}</diff>
      <filename>c/bloopsaphone.c</filename>
    </modified>
    <modified>
      <diff>@@ -41,7 +41,6 @@ typedef struct {
 
 typedef struct {
   bloopsaphone *P;
-  int tempo;
   int nlen, capa;
   bloopsanote *notes;
 
@@ -66,6 +65,7 @@ typedef struct {
 
 typedef struct {
   void *stream;
+  int tempo;
   float volume;
   bloopsatrack *tracks[BLOOPS_MAX_TRACKS];
   unsigned char play;
@@ -76,10 +76,14 @@ typedef struct {
 //
 bloops *bloops_new();
 void bloops_destroy(bloops *);
+bloopsaphone *bloops_square();
 bloopsaphone *bloops_load(char *);
 void bloops_clear(bloops *);
+void bloops_tempo(bloops *, int tempo);
 void bloops_track_at(bloops *, bloopsatrack *, int);
+void bloops_track_destroy(bloopsatrack *);
 void bloops_play(bloops *);
+int bloops_is_done(bloops *);
 bloopsatrack *bloops_track(bloops *, bloopsaphone *, char *, int);
 bloopsatrack *bloops_track2(bloops *, bloopsaphone *, char *);
 char *bloops_track_str(bloopsatrack *);</diff>
      <filename>c/bloopsaphone.h</filename>
    </modified>
    <modified>
      <diff>@@ -15,20 +15,19 @@ usage()
 int
 main(int argc, char *argv[])
 {
+  char *str;
   if (argc &gt; 1) {
     bloops *B = bloops_new();
-    bloopsaphone *P = bloops_load(&quot;tone.bloo&quot;);
-    bloopsaphone *P2 = bloops_load(&quot;shot.bloo&quot;);
-    bloopsaphone *P3 = bloops_load(&quot;jump.bloo&quot;);
-    bloopsatrack *track = bloops_track2(B, P, &quot;C 4 A A B 4 A A&quot;);
-    bloopsatrack *track2 = bloops_track2(B, P2, &quot;4 C 4 A 4 B 4 A&quot;);
-    bloopsatrack *track3 = bloops_track2(B, P3, &quot;A C A 4 4 4 A A&quot;);
-    printf(&quot;%s\n&quot;, bloops_track_str(track));
+    bloops_tempo(B, 320);
+    bloopsaphone *P = bloops_square();
+    bloopsatrack *track = bloops_track2(B, P, &quot;c5 c6 b4 b5 d5 d6 e5 e6&quot;);
+    printf(&quot;%s\n&quot;, str = bloops_track_str(track));
     bloops_track_at(B, track, 0);
-    bloops_track_at(B, track2, 1);
-    bloops_track_at(B, track3, 2);
     bloops_play(B);
-    sleep(8);
+    while (!bloops_is_done(B))
+      sleep(1);
+    free(P); free(str);
+    bloops_track_destroy(track);
     bloops_destroy(B);
     return 0;
   }</diff>
      <filename>c/bloopsawhat.c</filename>
    </modified>
    <modified>
      <diff>@@ -115,7 +115,6 @@ bloops_track(bloops *B, bloopsaphone *P, char *track, int tracklen)
   S-&gt;P = P;
   S-&gt;nlen = 0;
   S-&gt;capa = 1024;
-  S-&gt;tempo = 120;
   S-&gt;notes = (bloopsanote *)calloc(sizeof(bloopsanote), 1024);
 
   p = track;</diff>
      <filename>c/notation.rl</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>76964f95eb526c1ee3fbda650f2f4445686dd0c7</id>
    </parent>
  </parents>
  <author>
    <name>_why</name>
    <email>why@whytheluckystiff.net</email>
  </author>
  <url>http://github.com/localhost/bloopsaphone/commit/314696689527884bf5ce1f12cac20fe3fa7e8e3d</url>
  <id>314696689527884bf5ce1f12cac20fe3fa7e8e3d</id>
  <committed-date>2009-02-11T23:46:07-08:00</committed-date>
  <authored-date>2009-02-11T23:46:07-08:00</authored-date>
  <message> * c/bloopsaphone.c: freeing of memory.</message>
  <tree>bf74d9a8b8dbd9da02dff7aede692211bc264e62</tree>
  <committer>
    <name>_why</name>
    <email>why@whytheluckystiff.net</email>
  </committer>
</commit>
