Save This Page
Home » openjdk-7 » com.sun.media » sound » [javadoc | source]
    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.ArrayList;
   28   import java.util.Arrays;
   29   import java.util.List;
   30   
   31   import javax.sound.midi.Instrument;
   32   import javax.sound.midi.Patch;
   33   import javax.sound.midi.Soundbank;
   34   import javax.sound.midi.SoundbankResource;
   35   
   36   /**
   37    * A simple soundbank that contains instruments and soundbankresources.
   38    *
   39    * @author Karl Helgason
   40    */
   41   public class SimpleSoundbank implements Soundbank {
   42   
   43       String name = "";
   44       String version = "";
   45       String vendor = "";
   46       String description = "";
   47       List<SoundbankResource> resources = new ArrayList<SoundbankResource>();
   48       List<Instrument> instruments = new ArrayList<Instrument>();
   49   
   50       public String getName() {
   51           return name;
   52       }
   53   
   54       public String getVersion() {
   55           return version;
   56       }
   57   
   58       public String getVendor() {
   59           return vendor;
   60       }
   61   
   62       public String getDescription() {
   63           return description;
   64       }
   65   
   66       public void setDescription(String description) {
   67           this.description = description;
   68       }
   69   
   70       public void setName(String name) {
   71           this.name = name;
   72       }
   73   
   74       public void setVendor(String vendor) {
   75           this.vendor = vendor;
   76       }
   77   
   78       public void setVersion(String version) {
   79           this.version = version;
   80       }
   81   
   82       public SoundbankResource[] getResources() {
   83           return resources.toArray(new SoundbankResource[resources.size()]);
   84       }
   85   
   86       public Instrument[] getInstruments() {
   87           Instrument[] inslist_array
   88                   = instruments.toArray(new Instrument[resources.size()]);
   89           Arrays.sort(inslist_array, new ModelInstrumentComparator());
   90           return inslist_array;
   91       }
   92   
   93       public Instrument getInstrument(Patch patch) {
   94           int program = patch.getProgram();
   95           int bank = patch.getBank();
   96           boolean percussion = false;
   97           if (patch instanceof ModelPatch)
   98               percussion = ((ModelPatch)patch).isPercussion();
   99           for (Instrument instrument : instruments) {
  100               Patch patch2 = instrument.getPatch();
  101               int program2 = patch2.getProgram();
  102               int bank2 = patch2.getBank();
  103               if (program == program2 && bank == bank2) {
  104                   boolean percussion2 = false;
  105                   if (patch2 instanceof ModelPatch)
  106                       percussion2 = ((ModelPatch)patch2).isPercussion();
  107                   if (percussion == percussion2)
  108                       return instrument;
  109               }
  110           }
  111           return null;
  112       }
  113   
  114       public void addResource(SoundbankResource resource) {
  115           if (resource instanceof Instrument)
  116               instruments.add((Instrument) resource);
  117           else
  118               resources.add(resource);
  119       }
  120   
  121       public void removeResource(SoundbankResource resource) {
  122           if (resource instanceof Instrument)
  123               instruments.remove((Instrument) resource);
  124           else
  125               resources.remove(resource);
  126       }
  127   
  128       public void addInstrument(Instrument resource) {
  129           instruments.add(resource);
  130       }
  131   
  132       public void removeInstrument(Instrument resource) {
  133           instruments.remove(resource);
  134       }
  135   
  136       public void addAllInstruments(Soundbank soundbank) {
  137           for (Instrument ins : soundbank.getInstruments())
  138               addInstrument(ins);
  139       }
  140   
  141       public void removeAllInstruments(Soundbank soundbank) {
  142           for (Instrument ins : soundbank.getInstruments())
  143               removeInstrument(ins);
  144       }
  145   }

Save This Page
Home » openjdk-7 » com.sun.media » sound » [javadoc | source]