Project

General

Profile

« Previous | Next » 

Revision 6b0b4f60

Added by Leszek Koltunski almost 7 years ago

Fixes for removing effects.

View differences:

src/main/java/org/distorted/library/main/EffectQueue.java
35 35
  private static final int DETACH = 1;
36 36
  private static final int DETALL = 2;
37 37

  
38
  protected int mNumEffects;
38
  protected int mNumEffects;      // 'ToBe' will be more than mNumEffects if doWork() hasn't
39
  protected int mNumEffectsToBe;  // added them yet (or less if it hasn't removed some yet)
39 40
  protected float[] mUniforms;
40 41
  protected long[] mCurrentDuration;
41 42
  protected Effect[] mEffects;
......
48 49

  
49 50
  private ArrayList<DistortedNode> mNodes = null;
50 51
  private long mID;
51
  private int mNumEffectsToBe; // this will be more than mNumEffects if doWork hasn't really added them yet
52 52
  private static boolean mCreated;
53 53
  private int mIndex;
54
  private int mNumUniforms;
55 54

  
56 55
  private class Job
57 56
    {
58 57
    int type;
59
    int index;
60 58
    boolean notify;
61 59
    Effect effect;
62 60

  
63
    Job(int t, int i, boolean n, Effect e)
61
    Job(int t, boolean n, Effect e)
64 62
      {
65 63
      type  = t;
66
      index = i;
67 64
      notify= n;
68 65
      effect= e;
69 66
      }
......
85 82
    mNumEffectsToBe     = 0;
86 83
    mDistortedEffectsID = id;
87 84
    mIndex              = index;
88
    mNumUniforms        = numUniforms;
89 85

  
90 86
    int max = mMax[mIndex];
91 87

  
92 88
    if( max>0 )
93 89
      {
94
      mUniforms        = new float[mNumUniforms*max];
90
      mUniforms        = new float[numUniforms*max];
95 91
      mCurrentDuration = new long[max];
96 92
      mEffects         = new Effect[max];
97 93
      mName            = new int[max];
......
198 194
      mEffects[j]         = mEffects[j+1];
199 195
      mCurrentDuration[j] = mCurrentDuration[j+1];
200 196
      mName[j]            = mName[j+1];
201

  
202
      for(int k=0; k<mNumUniforms; k++)
203
        mUniforms[mNumUniforms*j+k] = mUniforms[mNumUniforms*(j+1)+k];
204 197
      }
205 198

  
206 199
    mEffects[mNumEffects] = null;
......
213 206

  
214 207
  synchronized int removeByName(EffectName name)
215 208
    {
209
    int ret = 0;
210

  
216 211
    for(int i=0; i<mNumEffects; i++)
217 212
      {
218 213
      if( mEffects[i].getName() == name )
219 214
        {
220
        mJobs.add(new Job(DETACH,i,true,null));
221
        DistortedMaster.newSlave(this);
222
        mNumEffectsToBe--;
223
        return 1;
215
        mJobs.add(new Job(DETACH,true,mEffects[i]));
216
        ret++;
224 217
        }
225 218
      }
226 219

  
227
    return 0;
220
    if( ret>0 )
221
      {
222
      DistortedMaster.newSlave(this);
223
      mNumEffectsToBe-=ret;
224
      }
225

  
226
    return ret;
228 227
    }
229 228

  
230 229
///////////////////////////////////////////////////////////////////////////////////////////////////
......
235 234
      {
236 235
      if( mEffects[i].getID() == id )
237 236
        {
238
        mJobs.add(new Job(DETACH,i,true,null));
237
        mJobs.add(new Job(DETACH,true,mEffects[i]));
239 238
        DistortedMaster.newSlave(this);
240 239
        mNumEffectsToBe--;
241 240
        return 1;
......
253 252
      {
254 253
      if( mEffects[i]==effect )
255 254
        {
256
        mJobs.add(new Job(DETACH,i,true,null));
255
        mJobs.add(new Job(DETACH,true,mEffects[i]));
257 256
        DistortedMaster.newSlave(this);
258 257
        mNumEffectsToBe--;
259 258
        return 1;
......
269 268

  
270 269
  synchronized int abortAll(boolean notify)
271 270
    {
272
    mJobs.add(new Job(DETALL,0,notify,null));
271
    mJobs.add(new Job(DETALL,notify,null));
273 272
    DistortedMaster.newSlave(this);
274 273
    mNumEffectsToBe = 0;
275 274
    return mNumEffects;
......
284 283
      //android.util.Log.e("queue", "scheduling future add of "+effect.getName().name()+" to "+mNumEffectsToBe+" id="+effect.getID());
285 284
      //android.util.Log.e("queue", "queue id="+mDistortedEffectsID);
286 285

  
287
      mJobs.add(new Job(ATTACH,mNumEffectsToBe,false,effect));
286
      mJobs.add(new Job(ATTACH,false,effect));
288 287
      DistortedMaster.newSlave(this);
289 288
      mNumEffectsToBe++;
290 289
      return true;
......
312 311

  
313 312
      switch(job.type)
314 313
        {
315
        case ATTACH: android.util.Log.e("queue", "DistortedEffects ID: "+mDistortedEffectsID+" bank:"+job.index+
316
                                        " attaching effectID="+job.effect.getID()+" ("+job.effect.getName().name()+")");
314
        case ATTACH: //android.util.Log.e("queue", "DisEffects ID: "+mDistortedEffectsID+" bank:"+mNumEffects+
315
                     //                   " attaching effectID="+job.effect.getID()+" ("+job.effect.getName().name()+")");
317 316

  
318
                     mCurrentDuration[job.index] = 0;
319
                     mEffects[job.index] = job.effect;
320
                     mName[job.index] = job.effect.getName().ordinal();
317
                     mCurrentDuration[mNumEffects] = 0;
318
                     mEffects[mNumEffects] = job.effect;
319
                     mName[mNumEffects] = job.effect.getName().ordinal();
321 320
                     mNumEffects++;
321
                     //android.util.Log.d("queue", "DisEffects ID: "+mDistortedEffectsID+
322
                     //        " success attaching, num to be:"+mNumEffectsToBe+" num:"+mNumEffects);
323

  
322 324
                     break;
323
        case DETACH: remove(job.index);
325
        case DETACH: //android.util.Log.e("queue", "DisEffects ID: "+mDistortedEffectsID+" detaching effect "+
326
                     //                             job.effect.getID());
327
                     for(int j=0; j<mNumEffects; j++)
328
                       {
329
                       if (mEffects[j] == job.effect)
330
                         {
331
                         remove(j);
332
                         //android.util.Log.d("queue", "DisEffects ID: "+mDistortedEffectsID+
333
                         //    " success detaching, num to be:"+mNumEffectsToBe+" num:"+mNumEffects);
334

  
335
                         break;
336
                         }
337
                       }
324 338
                     break;
325 339
        case DETALL: for(int j=0; j<mNumEffects; j++ )
326 340
                       {

Also available in: Unified diff