Beispiel #1
0
        public NoteEventEditDialog(Measure Measure, NoteMessage msg) : this(Measure) {
            nudVelocity.Value = msg.Velocity;

            StyleTime t = StyleTime.FromStyleTimestamp(msg.TotalTime, Measure);

            this.tbTimeBar.Text    = t.Bar.ToString();
            this.tbTimeBeat.Text   = t.Beat.ToString();
            this.tbTimeCPT.Text    = t.ClockPulseTime.ToString();
            this.nudVelocity.Value = msg.Velocity;
        }
        public void Play()
        {
            do
            {
                Player.Play();

                while (Player.Position < Player.TotalTime / (480f / this.Measure.Denominator))
                {
                    StyleTime t = StyleTime.FromStyleTimestamp((int)(Player.Position * 120), this.Measure);
                    pbBeat.Value     = t.Beat;
                    pbPosition.Value = (t.RawTime > pbPosition.Maximum) ? pbPosition.Maximum : t.RawTime;

                    lMeasure.Text = String.Format("{0}/{1}", t.Beat, t.Bar);

                    System.Threading.Thread.Sleep(50);
                    Application.DoEvents();
                }

                Player.Stop();
                Player.Rewind();
            }while (cbLoop.Checked);

            this.Close();
        }
        private void btnPlay_Click(object sender, EventArgs e)
        {
            dev.Open();
            Clock clock = new Clock(this.data.Tempo);

            bool ProgramSent = false;

            if (this.instr == TomiSoft.RolandStyleReader.Instrument.Drum)
            {
                dev.SendProgramChange(Channel.Channel10, Midi.Instrument.SteelDrums);
                ProgramSent = true;
            }
            else if (this.instr == TomiSoft.RolandStyleReader.Instrument.Bass)
            {
                dev.SendProgramChange(Channel.Channel2, Midi.Instrument.AcousticBass);
                ProgramSent = true;
            }

            float LastMsgTime = 0;
            int   LastTime    = 0;

            try {
                var Messages = from Current in this.data.data
                               where
                               Current.Arrangement == (this.IsBasic ? Arrangement.Basic : Arrangement.Advanced) &&
                               Current.Part == this.Part &&
                               Current.Instrument == this.instr &&
                               Current.ChordType == this.ctype
                               select Current;

                foreach (var Entry in Messages)
                {
                    if (Entry.Message.MessageType == MidiMessageType.Note)
                    {
                        clock.Schedule(this.ToMessage(Entry.Message, dev, clock, out LastMsgTime));
                        LastTime = Entry.Message.TotalTime + ((TomiSoft.RolandStyleReader.NoteMessage)Entry.Message).Length;
                    }

                    else if (Entry.Message.MessageType == MidiMessageType.ProgramChange)
                    {
                        if (!ProgramSent)
                        {
                            TomiSoft.RolandStyleReader.ProgramChangeMessage msg = (TomiSoft.RolandStyleReader.ProgramChangeMessage)Entry.Message;
                            dev.SendProgramChange(Channel.Channel4, (Midi.Instrument)msg.Program);
                        }
                    }
                }
            }
            catch (NoteValueOutOfRangeException) {
                MessageBox.Show(
                    "Note number must be in range 0-127",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
                return;
            }
            catch (NoteVelocityOutOfRangeException) {
                MessageBox.Show(
                    "Note velocity must be in range 0-127",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
                return;
            }
            catch (Exception) {
                MessageBox.Show(
                    "The style does not contain information for the selected part",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
                return;
            }

            pbPlaybackPosition.Maximum = LastTime;

            clock.Start();

            while (clock.Time <= LastMsgTime)
            {
                System.Threading.Thread.Sleep(50);

                StyleTime t = StyleTime.FromStyleTimestamp((int)(clock.Time * 120), this.data.Measure);
                lFriendlyTime.Text = String.Format("{0}.{1}.{2}", t.Bar, t.Beat, t.ClockPulseTime);
                lTotalTime.Text    = t.RawTime.ToString();

                pbBeat.Value             = t.Beat;
                pbPlaybackPosition.Value = (t.RawTime > pbPlaybackPosition.Maximum) ? pbPlaybackPosition.Maximum : t.RawTime;
                Application.DoEvents();
            }

            clock.Stop();
            dev.Close();

            pbBeat.Value             = 0;
            pbPlaybackPosition.Value = 0;
            lFriendlyTime.Text       = "0.0.0";
            lTotalTime.Text          = "0";
        }