using System; using System.Collections; using System.Collections.Generic; namespace Wavelet_Tracker { public class AMSynthMachine : MachineParameterisedBase { private const string type = "AM Synth"; private const string author = "Internal"; private const int version = 1; private ArrayList playingNotes; private WaveformSample waveform = null; private EnvelopeSample envelope = null; public AMSynthMachine(string name) : base(type, author, version, name) { playingNotes = new ArrayList(); machineLimitations = MachineLimitations.EmitsPCM; } protected override void endProductionImpl(long interval) { //long endTime = playTime + interval; List incomingNotes = inputs[0].buffer.getForProcessing(playTime, interval, true); for (int x = 0; x < incomingNotes.Count; x++) { if (incomingNotes[x] is NoteEvent) { NoteEvent note = (NoteEvent)incomingNotes[x]; float volume = 1.0f; try { volume = (float)((note.metadata.getAttribute("Volume"))); } catch (Exception) { } double notePitch = ScaleDefinition.getNotePitch(note.scale, note.note, note.fineTune); playingNotes.Add(new PCMOscillator((float) notePitch, volume, waveform, envelope, note.startTime)); } } for (int x = 0; x < playingNotes.Count; x++) { List events = ((PCMOscillator)(playingNotes[x])).getEvents(interval); if (events != null) { outputs[0].buffer.addAllEvents(events); } else { playingNotes.RemoveAt(x); x--; } } } protected override void endSeekImpl(long seekTime) { playingNotes.Clear(); } protected override void endSetupParametersImpl() { parameters = new MachineParameter[2]; MachineParameterDiscrete param = new MachineParameterDiscrete("Envelope", 0, 0, 999); parameters[0] = param; param = new MachineParameterDiscrete("Waveform", 0, 0, 999); parameters[1] = param; } protected override void endSetupInputOutputImpl() { outputs = new MachineConnection[1]; outputs[0] = new MachineConnection("Sound Output"); inputs = new MachineConnection[1]; inputs[0] = new MachineConnection("Note Input"); } protected override void endTickImpl(ArrayList parameterChanges) { foreach (MachineParameterChange change in parameterChanges) { if (change.parameter == parameters[0]) { Sample s = App.samples.getSample((int) change.newValue); if (s is EnvelopeSample) { envelope = (EnvelopeSample)s; } } if (change.parameter == parameters[1]) { Sample s = App.samples.getSample((int)change.newValue); if (s is WaveformSample) { waveform = (WaveformSample)s; } } } } } }