Project

General

Profile

« Previous | Next » 

Revision 6b0b4f60

Added by Leszek Koltunski over 7 years ago

Fixes for removing effects.

View differences:

src/main/java/org/distorted/library/main/DistortedEffects.java
464 464
 */
465 465
  public DistortedEffects()
466 466
    {
467
    android.util.Log.e("distEffects", "constr1");
468 467
    mID = ++mNextID;
469 468
    initializeEffectLists(this,0);
470 469
    }
......
481 480
 */
482 481
  public DistortedEffects(DistortedEffects dc, int flags)
483 482
    {
484
    android.util.Log.e("distEffects", "constr2");
485 483
    mID = ++mNextID;
486 484
    initializeEffectLists(dc,flags);
487 485
    }
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
                       {
src/main/java/org/distorted/library/main/EffectQueueFragment.java
71 71
        if( mEffects[i].isUnity( mUniforms, NUM_UNIFORMS*i) )
72 72
          {
73 73
          remove(i--);
74
          mNumEffectsToBe--;
74 75
          continue;
75 76
          }
76 77
        }
src/main/java/org/distorted/library/main/EffectQueueMatrix.java
302 302
          EffectMessageSender.newMessage( mListeners.get(j), EffectMessage.EFFECT_FINISHED, mEffects[i].getID(), mDistortedEffectsID);
303 303

  
304 304
        if( mEffects[i].isUnity( mUniforms, NUM_UNIFORMS*i) )
305
          {
305 306
          remove(i--);
307
          mNumEffectsToBe--;
308
          }
306 309
        }
307 310
      }
308 311
     
src/main/java/org/distorted/library/main/EffectQueuePostprocess.java
192 192
        if( mEffects[i].isUnity( mUniforms, NUM_UNIFORMS*i) )
193 193
          {
194 194
          remove(i--);
195
          mNumEffectsToBe--;
195 196
          continue;
196 197
          }
197 198
        }
src/main/java/org/distorted/library/main/EffectQueueVertex.java
71 71
        if( mEffects[i].isUnity( mUniforms, NUM_UNIFORMS*i) )
72 72
          {
73 73
          remove(i--);
74
          mNumEffectsToBe--;
74 75
          continue;
75 76
          }
76 77
        }

Also available in: Unified diff