Example #1
0
        public void AddNote(ISampleMaker voice, int step, int duration)
        {
            StepEvent stepEvent = null;

            if (this.stepEvents.ContainsKey(step))
            {
                stepEvent = this.stepEvents[step];
            }
            else
            {
                stepEvent = new StepEvent();
                this.stepEvents.Add(step, stepEvent);
            }
            stepEvent.Step = step;
            VoiceNote note = new VoiceNote();

            note.Duration = duration;
            note.Voice    = voice;
            stepEvent.VoiceNotes.Add(voice, note);
        }
Example #2
0
        virtual protected void ProcessCurrentStep()
        {
            if (this.stepIndex == 0)
            {
                for (int i = this.voicesInPlay.Count - 1; i >= 0; i--)
                {
                    VoiceNote note = this.voicesInPlay[i];
                    note.Elapsed = 0;
                    note.Voice.Reset();
                    if (note.Voice is IVoice)
                    {
                        ((IVoice)note.Voice).Envelope.Reset();
                    }
                    this.voicesInPlay.RemoveAt(i);
                }
            }

            //Increment duration of voices in play
            foreach (VoiceNote item in this.voicesInPlay)
            {
                item.Elapsed++;
            }

            //remove voices whose duration has completed
            for (int i = this.voicesInPlay.Count - 1; i >= 0; i--)
            {
                VoiceNote note = this.voicesInPlay[i];

                if (note.Voice is IVoice)
                {
                    if (note.Elapsed >= note.Duration)
                    {
                        IVoice voice = (IVoice)note.Voice;
                        if (!voice.Envelope.Releasing)
                        {
                            voice.Envelope.Release();
                        }
                        else if (!voice.Envelope.Active)
                        {
                            this.voicesInPlay.RemoveAt(i);
                            note.Elapsed = 0;
                            note.Voice.Reset();
                            voice.Envelope.Reset();
                        }
                    }
                }
                else
                {
                    if (note.Elapsed >= note.Duration)
                    {
                        this.voicesInPlay.RemoveAt(i);
                        note.Elapsed = 0;
                        note.Voice.Reset();
                        if (note.Voice is IVoice)
                        {
                            ((IVoice)note.Voice).Envelope.Reset();
                        }
                    }
                }

                if ((note.Voice is IVoice == false && note.Elapsed >= note.Duration) ||
                    (note.Voice is IVoice && note.Elapsed >= note.Duration && ((IVoice)note.Voice).Envelope.Active == false))
                {
                    this.voicesInPlay.RemoveAt(i);
                    note.Elapsed = 0;
                    note.Voice.Reset();
                    if (note.Voice is IVoice)
                    {
                        ((IVoice)note.Voice).Envelope.Reset();
                    }
                }
            }

            //add new notes on this step
            if (this.stepEvents.ContainsKey(this.stepIndex))
            {
                StepEvent stepEvent = this.stepEvents[this.stepIndex];
                foreach (ISampleMaker key in stepEvent.VoiceNotes.Keys)
                {
                    this.voicesInPlay.Add(stepEvent.VoiceNotes[key]);
                }
            }
        }