Beispiel #1
0
        /// <summary>
        /// Plays an MML string.
        /// </summary>
        /// <param name="mml">The MML string to play.</param>
        public void Play(string mml)
        {
            if (running)
            {
                StopRunning();
            }

            if (mml.Length == 0)
            {
                return;
            }

            StopAllNotes();

            ResetChannels();
            string[] channelMML = MMLStack.PreProcessMML(":0" + mml).Split(':');
            if (channelMML.Length == 1)
            {
                LoadChannelMML(0, channelMML[0]);
            }
            else
            {
                for (int i = 0; i < channelMML.Length; i++)
                {
                    if (channelMML[i] != string.Empty && char.IsDigit(channelMML[i][0]))
                    {
                        string chan = "" + channelMML[i][0];
                        if (channelMML[i].Length > 1 && char.IsDigit(channelMML[i][1]))
                        {
                            chan += channelMML[i][1];
                        }
                        LoadChannelMML(int.Parse(chan), channelMML[i].Substring(chan.Length));
                    }
                }
            }

            running = true;
            timer.Restart();
            while (running)
            {
                for (int index = 0; index < channels.Length; index++)
                {
                    channels[index].Update(timer.Elapsed.TotalSeconds);
                    running |= !channels[index].IsDone;
                }
            }
        }
Beispiel #2
0
        public MMLChannel(int channel,
                          GetNoteTimeDelegate noteTimeFunction,
                          ChangeTempoDelegate tempoFunction,
                          ChangeDutyDelegate dutyFunction,
                          SendEventDelegate eventFunction,
                          ChangeNoteStyleDelegate noteStyleFunction,
                          ChangeEnvelopeDelegate changeEnvelopeFunction)
        {
            channelID = channel;

            GetNoteTime     = noteTimeFunction;
            ChangeTempo     = tempoFunction;
            SendEvent       = eventFunction;
            ChangeDuty      = dutyFunction;
            ChangeNoteStyle = noteStyleFunction;
            ChangeEnvelope  = changeEnvelopeFunction;

            mStack = new MMLStack();

            ResetChannelDefaults();
        }
Beispiel #3
0
        public MMLChannel(int channel,
			GetNoteTimeDelegate noteTimeFunction,
			ChangeTempoDelegate tempoFunction,
			ChangeDutyDelegate dutyFunction,
			SendEventDelegate eventFunction,
			ChangeNoteStyleDelegate noteStyleFunction,
			ChangeEnvelopeDelegate changeEnvelopeFunction)
        {
            this.channelID = channel;

            this.GetNoteTime = noteTimeFunction;
            this.ChangeTempo = tempoFunction;
            this.SendEvent = eventFunction;
            this.ChangeDuty = dutyFunction;
            this.ChangeNoteStyle = noteStyleFunction;
            this.ChangeEnvelope = changeEnvelopeFunction;

            this.mStack = new MMLStack();

            this.ResetChannelDefaults();
        }