jdk/src/share/classes/com/sun/media/sound/AbstractMixer.java
author amenkov
Mon, 28 Feb 2011 18:36:33 +0300
changeset 8525 08f98f5a11df
parent 5506 202f599c92aa
child 18215 b2afd66ce6db
permissions -rw-r--r--
7013521: AudioSystem.write for AIFF files closes source audio stream Reviewed-by: dav
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.media.sound;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.sound.sampled.AudioFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.sound.sampled.AudioSystem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.sound.sampled.Control;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.sound.sampled.DataLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.sound.sampled.Mixer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.sound.sampled.Line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.sound.sampled.LineEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.sound.sampled.LineListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.sound.sampled.LineUnavailableException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Abstract Mixer.  Implements Mixer (with abstract methods) and specifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * some other common methods for use by our implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author Kara Kytle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
//$$fb 2002-07-26: let AbstractMixer be an AbstractLine and NOT an AbstractDataLine!
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
abstract class AbstractMixer extends AbstractLine implements Mixer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    //  STATIC VARIABLES
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    protected static final int PCM  = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    protected static final int ULAW = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    protected static final int ALAW = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    // IMMUTABLE PROPERTIES
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Info object describing this mixer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private final Mixer.Info mixerInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * source lines provided by this mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    protected Line.Info[] sourceLineInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * target lines provided by this mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected Line.Info[] targetLineInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * if any line of this mixer is started
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private boolean started = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * if this mixer had been opened manually with open()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * If it was, then it won't be closed automatically,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * only when close() is called manually.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private boolean manuallyOpened = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Supported formats for the mixer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    //$$fb DELETE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    //protected Vector formats = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    // STATE VARIABLES
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Source lines (ports) currently open
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    protected Vector sourceLines = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Target lines currently open.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    protected Vector targetLines = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Constructs a new AbstractMixer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @param mixer the mixer with which this line is associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param controls set of supported controls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    protected AbstractMixer(Mixer.Info mixerInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                            Control[] controls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                            Line.Info[] sourceLineInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                            Line.Info[] targetLineInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        // Line.Info, AbstractMixer, Control[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        super(new Line.Info(Mixer.class), null, controls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        // setup the line part
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.mixer = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if (controls == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            controls = new Control[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        // setup the mixer part
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        this.mixerInfo = mixerInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        this.sourceLineInfo = sourceLineInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        this.targetLineInfo = targetLineInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    // MIXER METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public Mixer.Info getMixerInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return mixerInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public Line.Info[] getSourceLineInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        Line.Info[] localArray = new Line.Info[sourceLineInfo.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        System.arraycopy(sourceLineInfo, 0, localArray, 0, sourceLineInfo.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        return localArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public Line.Info[] getTargetLineInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        Line.Info[] localArray = new Line.Info[targetLineInfo.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        System.arraycopy(targetLineInfo, 0, localArray, 0, targetLineInfo.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return localArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public Line.Info[] getSourceLineInfo(Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        Vector vec = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        for (i = 0; i < sourceLineInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            if (info.matches(sourceLineInfo[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                vec.addElement(sourceLineInfo[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        Line.Info[] returnedArray = new Line.Info[vec.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        for (i = 0; i < returnedArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            returnedArray[i] = (Line.Info)vec.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return returnedArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public Line.Info[] getTargetLineInfo(Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        Vector vec = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        for (i = 0; i < targetLineInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (info.matches(targetLineInfo[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                vec.addElement(targetLineInfo[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        Line.Info[] returnedArray = new Line.Info[vec.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        for (i = 0; i < returnedArray.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            returnedArray[i] = (Line.Info)vec.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return returnedArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public boolean isLineSupported(Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        for (i = 0; i < sourceLineInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            if (info.matches(sourceLineInfo[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        for (i = 0; i < targetLineInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            if (info.matches(targetLineInfo[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public abstract Line getLine(Line.Info info) throws LineUnavailableException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public abstract int getMaxLines(Line.Info info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    protected abstract void implOpen() throws LineUnavailableException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    protected abstract void implStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    protected abstract void implStop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    protected abstract void implClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public Line[] getSourceLines() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        Line[] localLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        synchronized(sourceLines) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            localLines = new Line[sourceLines.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            for (int i = 0; i < localLines.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                localLines[i] = (Line)sourceLines.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return localLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public Line[] getTargetLines() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        Line[] localLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        synchronized(targetLines) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            localLines = new Line[targetLines.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            for (int i = 0; i < localLines.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                localLines[i] = (Line)targetLines.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return localLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Default implementation always throws an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public void synchronize(Line[] lines, boolean maintainSync) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        throw new IllegalArgumentException("Synchronization not supported by this mixer.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Default implementation always throws an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public void unsynchronize(Line[] lines) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        throw new IllegalArgumentException("Synchronization not supported by this mixer.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Default implementation always returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public boolean isSynchronizationSupported(Line[] lines, boolean maintainSync) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    // OVERRIDES OF ABSTRACT DATA LINE METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * This implementation tries to open the mixer with its current format and buffer size settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public synchronized void open() throws LineUnavailableException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        open(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * This implementation tries to open the mixer with its current format and buffer size settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    protected synchronized void open(boolean manual) throws LineUnavailableException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (Printer.trace) Printer.trace(">> AbstractMixer: open()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        if (!isOpen()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            implOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            // if the mixer is not currently open, set open to true and send event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            setOpen(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            if (manual) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                manuallyOpened = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        if (Printer.trace) Printer.trace("<< AbstractMixer: open() succeeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    // METHOD FOR INTERNAL IMPLEMENTATION USE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * The default implementation of this method just determines whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * this line is a source or target line, calls open(no-arg) on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * mixer, and adds the line to the appropriate vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * The mixer may be opened at a format different than the line's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * format if it is a DataLine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    protected synchronized void open(Line line) throws LineUnavailableException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        if (Printer.trace) Printer.trace(">> AbstractMixer: open(line = " + line + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        // $$kk: 06.11.99: ignore ourselves for now
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (this.equals(line)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            if (Printer.trace) Printer.trace("<< AbstractMixer: open(" + line + ") nothing done");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        // source line?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        if (isSourceLine(line.getLineInfo())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            if (! sourceLines.contains(line) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                // call the no-arg open method for the mixer; it should open at its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                // default format if it is not open yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                open(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                // we opened successfully! add the line to the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                sourceLines.addElement(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            // target line?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            if(isTargetLine(line.getLineInfo())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                if (! targetLines.contains(line) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    // call the no-arg open method for the mixer; it should open at its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    // default format if it is not open yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    open(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    // we opened successfully!  add the line to the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    targetLines.addElement(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                if (Printer.err) Printer.err("Unknown line received for AbstractMixer.open(Line): " + line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        if (Printer.trace) Printer.trace("<< AbstractMixer: open(" + line + ") completed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * Removes this line from the list of open source lines and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * open target lines, if it exists in either.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * If the list is now empty, closes the mixer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    protected synchronized void close(Line line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        if (Printer.trace) Printer.trace(">> AbstractMixer: close(" + line + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        // $$kk: 06.11.99: ignore ourselves for now
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        if (this.equals(line)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            if (Printer.trace) Printer.trace("<< AbstractMixer: close(" + line + ") nothing done");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        sourceLines.removeElement(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        targetLines.removeElement(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if (Printer.debug) Printer.debug("AbstractMixer: close(line): sourceLines.size() now: " + sourceLines.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        if (Printer.debug) Printer.debug("AbstractMixer: close(line): targetLines.size() now: " + targetLines.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (sourceLines.isEmpty() && targetLines.isEmpty() && !manuallyOpened) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            if (Printer.trace) Printer.trace("AbstractMixer: close(" + line + "): need to close the mixer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (Printer.trace) Printer.trace("<< AbstractMixer: close(" + line + ") succeeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Close all lines and then close this mixer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    public synchronized void close() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (Printer.trace) Printer.trace(">> AbstractMixer: close()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (isOpen()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            // close all source lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            Line[] localLines = getSourceLines();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            for (int i = 0; i<localLines.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                localLines[i].close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            // close all target lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            localLines = getTargetLines();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            for (int i = 0; i<localLines.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                localLines[i].close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            implClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            // set the open state to false and send events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            setOpen(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        manuallyOpened = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (Printer.trace) Printer.trace("<< AbstractMixer: close() succeeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * Starts the mixer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    protected synchronized void start(Line line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        if (Printer.trace) Printer.trace(">> AbstractMixer: start(" + line + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        // $$kk: 06.11.99: ignore ourselves for now
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        if (this.equals(line)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            if (Printer.trace) Printer.trace("<< AbstractMixer: start(" + line + ") nothing done");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        // we just start the mixer regardless of anything else here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        if (!started) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            if (Printer.debug) Printer.debug("AbstractMixer: start(line): starting the mixer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            implStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            started = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        if (Printer.trace) Printer.trace("<< AbstractMixer: start(" + line + ") succeeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * Stops the mixer if this was the last running line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    protected synchronized void stop(Line line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        if (Printer.trace) Printer.trace(">> AbstractMixer: stop(" + line + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        // $$kk: 06.11.99: ignore ourselves for now
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        if (this.equals(line)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            if (Printer.trace) Printer.trace("<< AbstractMixer: stop(" + line + ") nothing done");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        Vector localSourceLines = (Vector)sourceLines.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        for (int i = 0; i < localSourceLines.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            // if any other open line is running, return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            // this covers clips and source data lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            if (localSourceLines.elementAt(i) instanceof AbstractDataLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                AbstractDataLine sourceLine = (AbstractDataLine)localSourceLines.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                if ( sourceLine.isStartedRunning() && (!sourceLine.equals(line)) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    if (Printer.trace) Printer.trace("<< AbstractMixer: stop(" + line + ") found running sourceLine: " + sourceLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        Vector localTargetLines = (Vector)targetLines.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        for (int i = 0; i < localTargetLines.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            // if any other open line is running, return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            // this covers target data lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            if (localTargetLines.elementAt(i) instanceof AbstractDataLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                AbstractDataLine targetLine = (AbstractDataLine)localTargetLines.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                if ( targetLine.isStartedRunning() && (!targetLine.equals(line)) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                    if (Printer.trace) Printer.trace("<< AbstractMixer: stop(" + line + ") found running targetLine: " + targetLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        // otherwise, stop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        if (Printer.debug) Printer.debug("AbstractMixer: stop(line): stopping the mixer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        started = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        implStop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if (Printer.trace) Printer.trace("<< AbstractMixer: stop(" + line + ") succeeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * Determines whether this is a source line for this mixer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * Right now this just checks whether it's supported, but should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * check whether it actually belongs to this mixer....
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    boolean isSourceLine(Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        for (int i = 0; i < sourceLineInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            if (info.matches(sourceLineInfo[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * Determines whether this is a target line for this mixer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * Right now this just checks whether it's supported, but should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * check whether it actually belongs to this mixer....
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    boolean isTargetLine(Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        for (int i = 0; i < targetLineInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            if (info.matches(targetLineInfo[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * Returns the first complete Line.Info object it finds that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * matches the one specified, or null if no matching Line.Info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * object is found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    Line.Info getLineInfo(Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        if (info == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        // $$kk: 05.31.99: need to change this so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        // the format and buffer size get set in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        // returned info object for data lines??
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        for (int i = 0; i < sourceLineInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            if (info.matches(sourceLineInfo[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                return sourceLineInfo[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        for (int i = 0; i < targetLineInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            if (info.matches(targetLineInfo[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                return targetLineInfo[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
}