|
4 | 4 | import com.jsyn.unitgen.VariableRateDataReader;
|
5 | 5 | import com.jsyn.unitgen.VariableRateMonoReader;
|
6 | 6 | import com.jsyn.unitgen.VariableRateStereoReader;
|
| 7 | +import com.softsynth.shared.time.TimeStamp; |
7 | 8 |
|
8 | 9 | import processing.core.PApplet;
|
9 | 10 |
|
@@ -120,11 +121,26 @@ protected void initiatePlayer() {
|
120 | 121 | // as long as their dataQueue is empty
|
121 | 122 | super.play(); // doesn't actually start playback, just adds the (silent) units
|
122 | 123 |
|
123 |
| - // this is kinda hack-ish, should maybe replace with its own boolean (and |
124 |
| - // overwrite public boolean isPlaying() to return that boolean instead) |
| 124 | + // as a consequence, the AudioSample class manages its isPlaying status |
| 125 | + // explicitly (see the overridden public boolean isPlaying() method below) |
125 | 126 | this.isPlaying = false;
|
126 | 127 | }
|
127 | 128 |
|
| 129 | + /** |
| 130 | + * Check whether this audiosample is currently playing. |
| 131 | + * @Override |
| 132 | + **/ |
| 133 | + public boolean isPlaying() { |
| 134 | + // this used to just return dataQueue.hasMore(), but this raises false |
| 135 | + // positives as .hasMore() still returns true for a split second after |
| 136 | + // dataQueue.clear() has been called. the AudioSample class therefore |
| 137 | + // manually sets the isPlaying boolean to true when playback commences, |
| 138 | + // but every time the user queries the playing status we check if the |
| 139 | + // queue has actually run out in the meantime. |
| 140 | + this.isPlaying = this.isPlaying & this.player.dataQueue.hasMore(); |
| 141 | + return this.isPlaying; |
| 142 | + } |
| 143 | + |
128 | 144 | /**
|
129 | 145 | * Change the amplitude/volume of this audiosample.
|
130 | 146 | *
|
@@ -380,7 +396,8 @@ private void playInternal() {
|
380 | 396 |
|
381 | 397 | private void playInternal(int startFrame, int numFrames) {
|
382 | 398 | this.setStartFrameCountOffset();
|
383 |
| - this.player.dataQueue.queue(this.sample, startFrame, numFrames); |
| 399 | + // only queueImmediate() guarantees that a directly subsequent call to .hasMore() returns true |
| 400 | + this.player.dataQueue.queueImmediate(this.sample, startFrame, numFrames, new TimeStamp(0.0)); |
384 | 401 | this.isPlaying = true;
|
385 | 402 | }
|
386 | 403 |
|
@@ -617,7 +634,7 @@ public void pause() {
|
617 | 634 | this.startFrame = this.positionFrame();
|
618 | 635 | this.setStartFrameCountOffset();
|
619 | 636 | } else {
|
620 |
| - Engine.printWarning("audio sample is already paused"); |
| 637 | + Engine.printWarning("trying to pause an audio sample that is not playing"); |
621 | 638 | }
|
622 | 639 | }
|
623 | 640 |
|
|
0 commit comments