Showing the changes to java/pkg/com/sun/media/sound/ModelConnectionBlock.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,135 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | +package com.sun.media.sound; | |
| 26 | + | |
| 27 | +import java.util.Arrays; | |
| 28 | + | |
| 29 | +/** | |
| 30 | + * Connection blocks are used to connect source variable | |
| 31 | + * to a destination variable. | |
| 32 | + * For example Note On velocity can be connected to output gain. | |
| 33 | + * In DLS this is called articulator and in SoundFonts (SF2) a modulator. | |
| 34 | + * | |
| 35 | + * @author Karl Helgason | |
| 36 | + */ | |
| 37 | +public class ModelConnectionBlock { | |
| 38 | + | |
| 39 | + // | |
| 40 | + // source1 * source2 * scale -> destination | |
| 41 | + // | |
| 42 | + private final static ModelSource[] no_sources = new ModelSource[0]; | |
| 43 | + private ModelSource[] sources = no_sources; | |
| 44 | + private double scale = 1; | |
| 45 | + private ModelDestination destination; | |
| 46 | + | |
| 47 | + public ModelConnectionBlock() { | |
| 48 | + } | |
| 49 | + | |
| 50 | + public ModelConnectionBlock(double scale, ModelDestination destination) { | |
| 51 | + this.scale = scale; | |
| 52 | + this.destination = destination; | |
| 53 | + } | |
| 54 | + | |
| 55 | + public ModelConnectionBlock(ModelSource source, | |
| 56 | + ModelDestination destination) { | |
| 57 | + if (source != null) { | |
| 58 | + this.sources = new ModelSource[1]; | |
| 59 | + this.sources[0] = source; | |
| 60 | + } | |
| 61 | + this.destination = destination; | |
| 62 | + } | |
| 63 | + | |
| 64 | + public ModelConnectionBlock(ModelSource source, double scale, | |
| 65 | + ModelDestination destination) { | |
| 66 | + if (source != null) { | |
| 67 | + this.sources = new ModelSource[1]; | |
| 68 | + this.sources[0] = source; | |
| 69 | + } | |
| 70 | + this.scale = scale; | |
| 71 | + this.destination = destination; | |
| 72 | + } | |
| 73 | + | |
| 74 | + public ModelConnectionBlock(ModelSource source, ModelSource control, | |
| 75 | + ModelDestination destination) { | |
| 76 | + if (source != null) { | |
| 77 | + if (control == null) { | |
| 78 | + this.sources = new ModelSource[1]; | |
| 79 | + this.sources[0] = source; | |
| 80 | + } else { | |
| 81 | + this.sources = new ModelSource[2]; | |
| 82 | + this.sources[0] = source; | |
| 83 | + this.sources[1] = control; | |
| 84 | + } | |
| 85 | + } | |
| 86 | + this.destination = destination; | |
| 87 | + } | |
| 88 | + | |
| 89 | + public ModelConnectionBlock(ModelSource source, ModelSource control, | |
| 90 | + double scale, ModelDestination destination) { | |
| 91 | + if (source != null) { | |
| 92 | + if (control == null) { | |
| 93 | + this.sources = new ModelSource[1]; | |
| 94 | + this.sources[0] = source; | |
| 95 | + } else { | |
| 96 | + this.sources = new ModelSource[2]; | |
| 97 | + this.sources[0] = source; | |
| 98 | + this.sources[1] = control; | |
| 99 | + } | |
| 100 | + } | |
| 101 | + this.scale = scale; | |
| 102 | + this.destination = destination; | |
| 103 | + } | |
| 104 | + | |
| 105 | + public ModelDestination getDestination() { | |
| 106 | + return destination; | |
| 107 | + } | |
| 108 | + | |
| 109 | + public void setDestination(ModelDestination destination) { | |
| 110 | + this.destination = destination; | |
| 111 | + } | |
| 112 | + | |
| 113 | + public double getScale() { | |
| 114 | + return scale; | |
| 115 | + } | |
| 116 | + | |
| 117 | + public void setScale(double scale) { | |
| 118 | + this.scale = scale; | |
| 119 | + } | |
| 120 | + | |
| 121 | + public ModelSource[] getSources() { | |
| 122 | + return Arrays.copyOf(sources, sources.length); | |
| 123 | + } | |
| 124 | + | |
| 125 | + public void setSources(ModelSource[] source) { | |
| 126 | + this.sources = source == null ? no_sources : Arrays.copyOf(source, source.length); | |
| 127 | + } | |
| 128 | + | |
| 129 | + public void addSource(ModelSource source) { | |
| 130 | + ModelSource[] oldsources = sources; | |
| 131 | + sources = new ModelSource[oldsources.length + 1]; | |
| 132 | + System.arraycopy(oldsources, 0, sources, 0, oldsources.length); | |
| 133 | + sources[sources.length - 1] = source; | |
| 134 | + } | |
| 135 | +} | |