view src/uk/ac/qmul/eecs/depic/daw/beads/BeadsSoundEngineFactory.java @ 2:c0412c81d274

Added documentation
author Fiore Martin <f.martin@qmul.ac.uk>
date Thu, 18 Feb 2016 18:35:26 +0000
parents 629262395647
children
line wrap: on
line source
/*  
 Cross-Modal DAW Prototype - Prototype of a simple Cross-Modal Digital Audio Workstation.

 Copyright (C) 2015  Queen Mary University of London (http://depic.eecs.qmul.ac.uk/)
	
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package uk.ac.qmul.eecs.depic.daw.beads;


import uk.ac.qmul.eecs.depic.daw.Parameter;
import uk.ac.qmul.eecs.depic.daw.Parameter.Type;
import uk.ac.qmul.eecs.depic.daw.Sample;
import uk.ac.qmul.eecs.depic.daw.Sonification;
import uk.ac.qmul.eecs.depic.daw.SoundEngineFactory;
import uk.ac.qmul.eecs.depic.daw.SoundWave;
import uk.ac.qmul.eecs.depic.daw.beads.sonification.BeadsSonification;

/**
 * 
 * Beads implementation of the {@code SoundEngineFactory}. All the object returned are typed with 
 * classes of this package. Therefore all the classes use the same Beads library and enjoy package 
 * access with one another. 
 * 
 * Also they can be safely downcasted in order to get full functionality. For example  
 * in {@code createParameter} the argument of type {@code SoundWave} is downcasted 
 * to {@code BeadsSoundWave}. This is guaranteed to be safe because the way SoundWave objects 
 * are created is through the {@code createSoundWave} method, which returns a BeadsSoundWave. 
 * 
 * This is in the spirit of the Facade design pattern. So a unique point of access to the package object
 * guarantees all the objects come from that package, despite implementing interfaces which are defined 
 * outside. 
 *  
 *  
 *
 */
public class BeadsSoundEngineFactory implements SoundEngineFactory {
	private static final int MAX_TRACK_SCALE_FACTOR = 10;
	private static final int MIN_CHUNCKSIZE = 8;
	private int minChunk;
	private int maxScaleFactor;
	private int initialScaleFactor;
	private Sonification sonification;
	
	public BeadsSoundEngineFactory(){
		minChunk = MIN_CHUNCKSIZE;
		maxScaleFactor = MAX_TRACK_SCALE_FACTOR;
		initialScaleFactor = MAX_TRACK_SCALE_FACTOR/2 + 1;
		sonification = new BeadsSonification();
	}
	
	@Override
	public SoundWave createSoundWave() {
		return new BeadsSoundWave(
				minChunk,
				maxScaleFactor,
				initialScaleFactor);
	}
	
	public BeadsSoundEngineFactory setSoundWaveParameters(int minChunk,int maxScaleFactor, int initialScaleFactor){
		this.minChunk = minChunk; 
		this.maxScaleFactor = maxScaleFactor;
		this.initialScaleFactor = initialScaleFactor;
		return this;
	}

	@Override
	public Parameter createParameter(Type type, SoundWave wave) {	
		if(Parameter.GAIN_TYPE.equals(type)) {
			return new GainParameter(((BeadsSoundWave)wave).ac,2);
		}else if(Parameter.PAN_TYPE.equals(type)) {  
			return new PanParameter(((BeadsSoundWave)wave).ac);
		}else{
			return null;
		}
	}

	@Override
	public Sonification getSharedSonification() {
		return sonification;
	}
	
	@Override
	public Sample createSample(String fileAbsolutePath) throws Exception {
		return new BeadsSampleWrapper(new net.beadsproject.beads.data.Sample(
				fileAbsolutePath,
				net.beadsproject.beads.data.Sample.Regime.newStreamingRegimeWithAging(1000, 1000)
			)
		);
	}

}