commit 34e43b0ad77efb424d83eae8a68b386e7b437a6a
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue May 7 21:06:19 2019 +0100

    Progress with DistortedCube.

diff --git a/src/main/java/org/distorted/library/effectqueue/EffectQueue.java b/src/main/java/org/distorted/library/effectqueue/EffectQueue.java
index 8bb5d11..467e716 100644
--- a/src/main/java/org/distorted/library/effectqueue/EffectQueue.java
+++ b/src/main/java/org/distorted/library/effectqueue/EffectQueue.java
@@ -337,7 +337,22 @@ public abstract class EffectQueue implements InternalMaster.Slave
     {
     if( mMax[mIndex]>mNumEffectsToBe || !mCreated )
       {
-      mJobs.add(new Job(ATTACH,0,false,effect));
+      mJobs.add(new Job(ATTACH,-1,false,effect));
+      InternalMaster.newSlave(this);
+      mNumEffectsToBe++;
+      return true;
+      }
+
+    return false;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public boolean add(Effect effect, int position)
+    {
+    if( mMax[mIndex]>mNumEffectsToBe || !mCreated )
+      {
+      mJobs.add(new Job(ATTACH,position,false,effect));
       InternalMaster.newSlave(this);
       mNumEffectsToBe++;
       return true;
@@ -373,9 +388,30 @@ public abstract class EffectQueue implements InternalMaster.Slave
                      break;
         case ATTACH: if( mMax[mIndex]>mNumEffects ) // it is possible that we have first
                        {                            // added effects and then lowered mMax
-                       mCurrentDuration[mNumEffects] = 0;
-                       mEffects[mNumEffects] = job.effect;
-                       mName[mNumEffects] = job.effect.getName().ordinal();
+                       int position = job.num;
+
+                       if( position==-1 )
+                         {
+                         mCurrentDuration[mNumEffects] = 0;
+                         mEffects[mNumEffects] = job.effect;
+                         mName[mNumEffects] = job.effect.getName().ordinal();
+                         }
+                       else if( position>=0 && position<=mNumEffects )
+                         {
+                         //android.util.Log.e("queue", "adding new effect to pos "+position);
+
+                         for(int j=mNumEffects; j>position; j--)
+                           {
+                           mCurrentDuration[j] = mCurrentDuration[j-1];
+                           mEffects[j]         = mEffects[j-1];
+                           mName[j]            = mName[j-1];
+                           }
+
+                         mCurrentDuration[position] = 0;
+                         mEffects[position] = job.effect;
+                         mName[position] = job.effect.getName().ordinal();
+                         }
+
                        mNumEffects++;
                        changed = true;
                        }
diff --git a/src/main/java/org/distorted/library/main/DistortedEffects.java b/src/main/java/org/distorted/library/main/DistortedEffects.java
index e117bd3..fc1d0ac 100644
--- a/src/main/java/org/distorted/library/main/DistortedEffects.java
+++ b/src/main/java/org/distorted/library/main/DistortedEffects.java
@@ -194,7 +194,7 @@ public class DistortedEffects
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- * Add a new Effect to our queue.
+ * Add a new Effect to the tail of our queue.
  *
  * @param effect The Effect to add.
  * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
@@ -204,4 +204,18 @@ public class DistortedEffects
     int num = effect.getType().ordinal();
     return mQueues[num].add(effect);
     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Add a new Effect to our queue at a specified position.
+ *
+ * @param effect The Effect to add.
+ * @param position the place in the effects queue where to add the new effect.
+ * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
+ */
+  public boolean apply(Effect effect, int position)
+    {
+    int num = effect.getType().ordinal();
+    return mQueues[num].add(effect,position);
+    }
   }
