Exemplo n.º 1
0
        // Clear and fill viewer.incipit
        #region old
        private void convertSequenceToIncipit()
        {
            bool tempoSet = false;

            //Suppression des elements de l'incipit
            viewer.ClearMusicalIncipit();
            viewer.AddMusicalSymbol(clef);
            viewer.AddMusicalSymbol(TimeSign);

            //Parcourt des différentes tracks

            musicProgressBar.Show();
            musicProgressBar.Value = 0;
            musicProgressBar.PerformStep();
            foreach (Track track in sequencer.Sequence)
            {
                //Parcourt des messages de la track
                foreach (MidiEvent notes in track.Iterator())
                {
                    musicProgressBar.Increment((int)(notes.AbsoluteTicks / track.Length * 100));
                    //Si c'est un channel message
                    if (notes.MidiMessage.MessageType == MessageType.Channel)
                    {
                        //cast dans le bon format
                        ChannelMessage      message      = (ChannelMessage)(notes.MidiMessage);
                        List <NoteBeamType> noteBeamList = new List <NoteBeamType> {
                            NoteBeamType.Single
                        };
                        byte[] intBytes = message.GetBytes();

                        if ((message.Command == ChannelCommand.NoteOn || message.Command == ChannelCommand.NoteOff) && notes.DeltaTicks != 0)
                        {
                            //Note - velocité
                            //Récupérartion octave+note
                            string[] tab    = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
                            int      pitch  = intBytes[1];
                            int      octave = pitch / 12 - 1;
                            int      note   = pitch % 12;

                            viewer.AddMusicalSymbol((new NoteSymb(tab[note], 0, octave, getDurationFromTick(notes.DeltaTicks, sequencer.Sequence.Division), Color.Black).getSymb()));
                        }
                    }
                    else if (notes.MidiMessage.MessageType == MessageType.Meta)
                    {
                        MetaMessage message = (MetaMessage)(notes.MidiMessage);

                        switch (message.MetaType)
                        {
                        case (MetaType.TrackName):
                            string content = "";
                            foreach (byte b in message.GetBytes())
                            {
                                content += (Char)b;
                            }
                            this.title.Text = content;
                            break;

                        case (MetaType.Tempo):
                            byte[] bytes = { 0, (message.GetBytes())[0], (message.GetBytes())[1], (message.GetBytes())[2] };

                            if (BitConverter.IsLittleEndian)
                            {
                                Array.Reverse(bytes);
                            }

                            int tempo = BitConverter.ToInt32(bytes, 0);
                            if (!tempoSet)
                            {
                                tempoSet        = true;
                                this.TempoValue = (int)(60000.0 / ((Double)tempo / 1000.0));
                                this.Tempo.Text = ((int)(60000.0 / ((Double)tempo / 1000.0))).ToString();
                            }
                            break;

                        case (MetaType.TimeSignature):
                            TimeSignature newTimeSign = new TimeSignature(TimeSignatureType.Numbers, (message.GetBytes())[0], Convert.ToUInt32(1 << (message.GetBytes())[1]));
                            viewer.ChangeMusicalSymbol(TimeSign, newTimeSign);
                            TimeSign = newTimeSign;
                            break;

                        case (MetaType.KeySignature):
                            if ((message.GetBytes())[0] != 0)
                            {
                                int key = (message.GetBytes())[0];
                                if (key > 7)
                                {
                                    key = key - 256;
                                }
                                ArmureSelect = MenuArmure_Default;
                                ToolStripMenuItem newArmure = getArmureItemFromKey(key);
                                changeArmure(newArmure, new Key(key));
                            }
                            break;
                        }
                    }
                }
            }
            musicProgressBar.Hide();
        }