package framework;

import java.util.ArrayList;
import framework.editors.SoundEditor;

/**
 * Represents a sound entity.
 *
 * A sound is represented basically by a frequency and a duration.
 * The basic wave is synthetised using a generator object.
 * It can then be modified by adding different modifiers.
 * It is the core of the model in our MVC design pattern implementation.
 */
public class Sound extends Observable {
    /**
     * Creates a Sound object.
     * @param  g the generator to be used
     * @param  f the frequency of the signal
     * @param  d the duration of the sound
     */
    public Sound(Generator g, int f, double d) {
        generator   = g;
        frequency   = f;
        duration    = d;
        data        = null;
        modifiers   = new ArrayList<Modifier>();

        generateSignal();
    }

    /**
     * Generate the signal data from the basic wave and modifiers.
     */
    public void generateSignal() {
        byte[] signal = generator.generate(frequency, duration, SAMPLE_RATE);

        foreach(Modifier m : modifiers)
            signal = m.apply(signal);

        data = signal;

        setChanged();
        notifyObservers(data);
    }

    /**
     * Add a new Modifier to the list.
     * @param m the new Modifier to be added
     */
    public void addModifier(Modifier m) {
        modifiers.add(m);
        generateSignal();
    }

    /**
     * Remove the specified Modifier from the list.
     * @param m the Modifier to be removed
     */
    public void removeModifier(Modifier m) {
        modifiers.remove(m);
        generateSignal();
    }

    /**
     * Instanciate a SoundEditor and hand back its reference.
     * @return the reference to the SoundEditor
     */
    public SoundEditor addEditor() {

    }

    private Generator           generator;
    private int                 frequency;  // Hertzs
    private double              duration;   // Milliseconds
    private byte[]              data;
    private ArrayList<Modifier> modifiers;

    // Constants
    private final int SAMPLE_RATE   = 44100;    // CD quality audio
    private final int MAX_16_BITS   = Short.MAX_VALUE;
}
@@ -44,46 +44,8 @@
 ist;
-%0Aimport framework.editors.SoundEditor;
 %0A%0A/*
@@ -209,66 +209,8 @@
 ct.%0A
- * It can then be modified by adding different modifiers.%0A
  * I
@@ -654,57 +654,8 @@
 ull;
-%0A        modifiers   = new ArrayList%3CModifier%3E();
 %0A%0A  
@@ -748,22 +748,8 @@
 wave
- and modifiers
 .%0A  
@@ -872,87 +872,8 @@
 );%0A%0A
-        foreach(Modifier m : modifiers)%0A            signal = m.apply(signal);%0A%0A
     
@@ -956,427 +956,8 @@
  %7D%0A%0A
-    /**%0A     * Add a new Modifier to the list.%0A     * @param m the new Modifier to be added%0A     */%0A    public void addModifier(Modifier m) %7B%0A        modifiers.add(m);%0A        generateSignal();%0A    %7D%0A%0A    /**%0A     * Remove the specified Modifier from the list.%0A     * @param m the Modifier to be removed%0A     */%0A    public void removeModifier(Modifier m) %7B%0A        modifiers.remove(m);%0A        generateSignal();%0A    %7D%0A%0A
     
@@ -1321,51 +1321,8 @@
 ata;
-%0A    private ArrayList%3CModifier%3E modifiers;
 %0A%0A  

Remove modifier system from the Sound class for the moment.