f@0: /* f@0: Cross-Modal DAW Prototype - Prototype of a simple Cross-Modal Digital Audio Workstation. f@0: f@0: Copyright (C) 2015 Queen Mary University of London (http://depic.eecs.qmul.ac.uk/) f@0: f@0: This program is free software: you can redistribute it and/or modify f@0: it under the terms of the GNU General Public License as published by f@0: the Free Software Foundation, either version 3 of the License, or f@0: (at your option) any later version. f@0: f@0: This program is distributed in the hope that it will be useful, f@0: but WITHOUT ANY WARRANTY; without even the implied warranty of f@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the f@0: GNU General Public License for more details. f@0: f@0: You should have received a copy of the GNU General Public License f@0: along with this program. If not, see . f@0: */ f@0: package uk.ac.qmul.eecs.depic.daw.beads; f@0: f@1: f@0: import uk.ac.qmul.eecs.depic.daw.Parameter; f@0: import uk.ac.qmul.eecs.depic.daw.Parameter.Type; f@1: import uk.ac.qmul.eecs.depic.daw.Sample; f@0: import uk.ac.qmul.eecs.depic.daw.Sonification; f@0: import uk.ac.qmul.eecs.depic.daw.SoundEngineFactory; f@0: import uk.ac.qmul.eecs.depic.daw.SoundWave; f@0: import uk.ac.qmul.eecs.depic.daw.beads.sonification.BeadsSonification; f@0: f@2: /** f@2: * f@2: * Beads implementation of the {@code SoundEngineFactory}. All the object returned are typed with f@2: * classes of this package. Therefore all the classes use the same Beads library and enjoy package f@2: * access with one another. f@2: * f@2: * Also they can be safely downcasted in order to get full functionality. For example f@2: * in {@code createParameter} the argument of type {@code SoundWave} is downcasted f@2: * to {@code BeadsSoundWave}. This is guaranteed to be safe because the way SoundWave objects f@2: * are created is through the {@code createSoundWave} method, which returns a BeadsSoundWave. f@2: * f@2: * This is in the spirit of the Facade design pattern. So a unique point of access to the package object f@2: * guarantees all the objects come from that package, despite implementing interfaces which are defined f@2: * outside. f@2: * f@2: * f@2: * f@2: */ f@0: public class BeadsSoundEngineFactory implements SoundEngineFactory { f@0: private static final int MAX_TRACK_SCALE_FACTOR = 10; f@0: private static final int MIN_CHUNCKSIZE = 8; f@0: private int minChunk; f@0: private int maxScaleFactor; f@0: private int initialScaleFactor; f@0: private Sonification sonification; f@0: f@0: public BeadsSoundEngineFactory(){ f@0: minChunk = MIN_CHUNCKSIZE; f@0: maxScaleFactor = MAX_TRACK_SCALE_FACTOR; f@0: initialScaleFactor = MAX_TRACK_SCALE_FACTOR/2 + 1; f@0: sonification = new BeadsSonification(); f@0: } f@0: f@0: @Override f@0: public SoundWave createSoundWave() { f@0: return new BeadsSoundWave( f@0: minChunk, f@0: maxScaleFactor, f@0: initialScaleFactor); f@0: } f@0: f@0: public BeadsSoundEngineFactory setSoundWaveParameters(int minChunk,int maxScaleFactor, int initialScaleFactor){ f@0: this.minChunk = minChunk; f@0: this.maxScaleFactor = maxScaleFactor; f@0: this.initialScaleFactor = initialScaleFactor; f@0: return this; f@0: } f@0: f@0: @Override f@0: public Parameter createParameter(Type type, SoundWave wave) { f@0: if(Parameter.GAIN_TYPE.equals(type)) { f@0: return new GainParameter(((BeadsSoundWave)wave).ac,2); f@0: }else if(Parameter.PAN_TYPE.equals(type)) { f@0: return new PanParameter(((BeadsSoundWave)wave).ac); f@0: }else{ f@0: return null; f@0: } f@0: } f@0: f@0: @Override f@0: public Sonification getSharedSonification() { f@0: return sonification; f@0: } f@1: f@1: @Override f@1: public Sample createSample(String fileAbsolutePath) throws Exception { f@1: return new BeadsSampleWrapper(new net.beadsproject.beads.data.Sample( f@1: fileAbsolutePath, f@1: net.beadsproject.beads.data.Sample.Regime.newStreamingRegimeWithAging(1000, 1000) f@1: ) f@1: ); f@1: } f@0: f@0: }