package y0;

import c1.C0406c;
import c1.InterfaceC0404a;
import com.jsyn.unitgen.y;
import q0.InterfaceC0696b;

/* JADX INFO: loaded from: classes.dex */
public class f {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private int f7065a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private c[] f7066b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private long f7067c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private InterfaceC0696b f7068d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private int f7069e = -1;

    class a implements InterfaceC0404a {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ int f7070b;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        final /* synthetic */ h f7071g;

        /* JADX INFO: renamed from: r, reason: collision with root package name */
        final /* synthetic */ double f7072r;

        /* JADX INFO: renamed from: x, reason: collision with root package name */
        final /* synthetic */ double f7073x;

        a(int i2, h hVar, double d2, double d3) {
            this.f7070b = i2;
            this.f7071g = hVar;
            this.f7072r = d2;
            this.f7073x = d3;
        }

        @Override // c1.InterfaceC0404a
        public void run() {
            c cVarD = f.this.d(this.f7070b);
            this.f7071g.a(cVarD.f7077a);
            cVarD.f7077a.noteOn(this.f7072r, this.f7073x, f.this.f().e());
        }
    }

    class b implements InterfaceC0404a {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ int f7075b;

        b(int i2) {
            this.f7075b = i2;
        }

        @Override // c1.InterfaceC0404a
        public void run() {
            c cVarE = f.this.e(this.f7075b);
            if (cVarE != null) {
                cVarE.f7077a.noteOff(f.this.f().e());
                f.this.i(this.f7075b);
            }
        }
    }

    public f(y[] yVarArr) {
        int length = yVarArr.length;
        this.f7065a = length;
        this.f7066b = new c[length];
        for (int i2 = 0; i2 < this.f7065a; i2++) {
            this.f7066b[i2] = new c(this, null);
            this.f7066b[i2].f7077a = yVarArr[i2];
        }
    }

    static /* synthetic */ long a(f fVar) {
        long j2 = fVar.f7067c;
        fVar.f7067c = 1 + j2;
        return j2;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public c d(int i2) {
        c cVarE = e(i2);
        if (cVarE == null) {
            cVarE = j();
        }
        cVarE.f7078b = i2;
        long j2 = this.f7067c;
        this.f7067c = 1 + j2;
        cVarE.f7080d = j2;
        cVarE.f7081e = true;
        return cVarE;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public c e(int i2) {
        for (c cVar : this.f7066b) {
            if (cVar.f7078b == i2) {
                return cVar;
            }
        }
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:20:0x0030  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private y0.f.c j() {
        /*
            r10 = this;
            y0.f$c[] r0 = r10.f7066b
            int r1 = r0.length
            r2 = 0
            r3 = 0
            r4 = r3
            r3 = r2
        L7:
            if (r4 >= r1) goto L34
            r5 = r0[r4]
            com.jsyn.unitgen.y r6 = r5.f7077a
            if (r6 != 0) goto L10
            return r5
        L10:
            if (r2 == 0) goto L1f
            boolean r6 = r5.f7081e
            if (r6 != 0) goto L31
            long r6 = r5.f7080d
            long r8 = r2.f7080d
            int r6 = (r6 > r8 ? 1 : (r6 == r8 ? 0 : -1))
            if (r6 >= 0) goto L31
            goto L30
        L1f:
            boolean r6 = r5.f7081e
            if (r6 == 0) goto L30
            if (r3 != 0) goto L26
            goto L2e
        L26:
            long r6 = r5.f7080d
            long r8 = r3.f7080d
            int r6 = (r6 > r8 ? 1 : (r6 == r8 ? 0 : -1))
            if (r6 >= 0) goto L31
        L2e:
            r3 = r5
            goto L31
        L30:
            r2 = r5
        L31:
            int r4 = r4 + 1
            goto L7
        L34:
            if (r2 == 0) goto L37
            return r2
        L37:
            return r3
        */
        throw new UnsupportedOperationException("Method not decompiled: y0.f.j():y0.f$c");
    }

    public InterfaceC0696b f() {
        if (this.f7068d == null) {
            this.f7068d = this.f7066b[0].f7077a.getUnitGenerator().getSynthesizer();
        }
        return this.f7068d;
    }

    public void g(int i2, C0406c c0406c) {
        f().c(c0406c, new b(i2));
    }

    public void h(int i2, double d2, double d3, h hVar, C0406c c0406c) {
        f().c(c0406c, new a(i2, hVar, d2, d3));
    }

    protected synchronized y i(int i2) {
        c cVarE = e(i2);
        if (cVarE == null) {
            return null;
        }
        cVarE.a();
        return cVarE.f7077a;
    }

    private class c {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        y f7077a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        int f7078b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        int f7079c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        long f7080d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        boolean f7081e;

        private c() {
            this.f7078b = -1;
            this.f7079c = -1;
        }

        public void a() {
            this.f7081e = false;
            this.f7080d = f.a(f.this);
        }

        /* synthetic */ c(f fVar, AbstractC0748e abstractC0748e) {
            this();
        }
    }
}
