aboutsummaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorPhil Burk <[email protected]>2016-11-27 13:57:49 -0800
committerGitHub <[email protected]>2016-11-27 13:57:49 -0800
commitbcd89345103f895b2b5fd508fca4cbe7af033861 (patch)
treed85f0687742a8865ba12ce21c1ac4c95ab9de1b1 /src/com
parenta6583e89166f7477a675cf3094a91b303ba7850a (diff)
parentff5e1fb0794cc65c32a7d9f51d03eba841eba4ad (diff)
Merge pull request #39 from philburk/issue-15-queue
Check for bounds when sample or envelope data is queued.
Diffstat (limited to 'src/com')
-rw-r--r--src/com/jsyn/ports/QueueDataCommand.java32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/com/jsyn/ports/QueueDataCommand.java b/src/com/jsyn/ports/QueueDataCommand.java
index 52025ae..c23fbcd 100644
--- a/src/com/jsyn/ports/QueueDataCommand.java
+++ b/src/com/jsyn/ports/QueueDataCommand.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,7 +22,7 @@ import com.softsynth.shared.time.ScheduledCommand;
/**
* A command that can be used to queue SequentialData to a UnitDataQueuePort. Here is an example of
* queuing data with a callback using this command.
- *
+ *
* <pre>
* <code>
* // Queue an envelope with a completion callback.
@@ -36,9 +36,9 @@ import com.softsynth.shared.time.ScheduledCommand;
* synth.queueCommand( command );
* </code>
* </pre>
- *
+ *
* The callback will be passed QueueDataEvents.
- *
+ *
* <pre>
* <code>
* class TestQueueCallback implements UnitDataQueueCallback
@@ -47,12 +47,12 @@ import com.softsynth.shared.time.ScheduledCommand;
* {
* System.out.println("CALLBACK: Envelope started.");
* }
- *
+ *
* public void looped( QueueDataEvent event )
* {
* System.out.println("CALLBACK: Envelope looped.");
* }
- *
+ *
* public void finished( QueueDataEvent event )
* {
* System.out.println("CALLBACK: Envelope finished.");
@@ -60,7 +60,7 @@ import com.softsynth.shared.time.ScheduledCommand;
* }
* </code>
* </pre>
- *
+ *
* @author Phil Burk 2009 Mobileer Inc
*/
public abstract class QueueDataCommand extends QueueDataEvent implements ScheduledCommand {
@@ -75,7 +75,11 @@ public abstract class QueueDataCommand extends QueueDataEvent implements Schedul
int numFrames) {
super(port);
- assert ((startFrame + numFrames) <= sequentialData.getNumFrames());
+ if ((startFrame + numFrames) > sequentialData.getNumFrames()) {
+ throw new IllegalArgumentException("tried to queue past end of data, " + (startFrame + numFrames));
+ } else if (startFrame < 0) {
+ throw new IllegalArgumentException("tried to queue before start of data, " + startFrame);
+ }
this.sequentialData = sequentialData;
this.currentData = sequentialData;
crossfadeData = new SequentialDataCrossfade();
@@ -89,7 +93,7 @@ public abstract class QueueDataCommand extends QueueDataEvent implements Schedul
/**
* If true then this item will be skipped if other items are queued after it. This flag allows
* you to queue lots of small pieces of sound without making the queue very long.
- *
+ *
* @param skipIfOthers
*/
public void setSkipIfOthers(boolean skipIfOthers) {
@@ -101,7 +105,7 @@ public abstract class QueueDataCommand extends QueueDataEvent implements Schedul
* better to use this flag than to clear the queue from the application because there could be a
* gap before the next item is available. This is most useful when combined with
* setCrossFadeIn().
- *
+ *
* @param immediate
*/
public void setImmediate(boolean immediate) {
@@ -134,7 +138,7 @@ public abstract class QueueDataCommand extends QueueDataEvent implements Schedul
/**
* Stop the unit that contains this port after this command has finished.
- *
+ *
* @param autoStop
*/
public void setAutoStop(boolean autoStop) {
@@ -145,7 +149,7 @@ public abstract class QueueDataCommand extends QueueDataEvent implements Schedul
* Set how many time the block should be repeated after the first time. For example, if you set
* numLoops to zero the block will only be played once. If you set numLoops to one the block
* will be played twice.
- *
+ *
* @param numLoops number of times to loop back
*/
public void setNumLoops(int numLoops) {
@@ -156,7 +160,7 @@ public abstract class QueueDataCommand extends QueueDataEvent implements Schedul
* Number of frames to cross fade from the previous block to this block. This can be used to
* avoid pops when making abrupt transitions. There must be frames available after the end of
* the previous block to use for crossfading. The crossfade is linear.
- *
+ *
* @param size
*/
public void setCrossFadeIn(int size) {