public void Load(string fileName)
        {
            var stream = new FileStream(fileName, FileMode.Open,
                                        FileAccess.Read, FileShare.Read);

            using (stream)
            {
                var newProperties = new MidiFileProperties();
                var reader        = new TrackReader();
                var newTracks     = new List <Track>();

                newProperties.Read(stream);

                for (int i = 0; i < newProperties.TrackCount; i++)
                {
                    reader.Read(stream);
                    reader.Track.Sequence = this;
                    reader.Track.FileType = this.FileType;
                    newTracks.Add(reader.Track);
                }

                properties = newProperties;
                tracks     = newTracks;
            }
        }
        /// <summary>
        /// Loads a MIDI file into the Sequence.
        /// </summary>
        /// <param name="fileName">
        /// The MIDI file's name.
        /// </param>
        public void Load(string fileName)
        {
            #region Require

            if (disposed)
            {
                throw new ObjectDisposedException("Sequence");
            }
            else if (IsBusy)
            {
                throw new InvalidOperationException();
            }
            else if (fileName == null)
            {
                //throw new ArgumentNullException("fileName");
                return; // LOL
            }

            #endregion

            FileStream stream = new FileStream(fileName, FileMode.Open,
                                               FileAccess.Read, FileShare.Read);

            using (stream)
            {
                MidiFileProperties newProperties = new MidiFileProperties();
                TrackReader        reader        = new TrackReader();
                List <Track>       newTracks     = new List <Track>();

                newProperties.Read(stream);

                for (int i = 0; i < newProperties.TrackCount; i++)
                {
                    reader.Read(stream);
                    newTracks.Add(reader.Track);
                }

                properties = newProperties;
                tracks     = newTracks;
            }

            #region Ensure

            Debug.Assert(Count == properties.TrackCount);

            #endregion
        }
Beispiel #3
0
        /// <summary>
        /// Loads a MIDI stream into the Sequence.
        /// </summary>
        /// <param name="fileStream">
        /// The MIDI file's stream.
        /// </param>
        public void Load(Stream fileStream)
        {
            #region Require

            if (disposed)
            {
                throw new ObjectDisposedException("Sequence");
            }
            else if (IsBusy)
            {
                throw new InvalidOperationException();
            }
            else if (fileStream == null)
            {
                throw new ArgumentNullException("fileStream");
            }

            #endregion

            using (fileStream)
            {
                MidiFileProperties newProperties = new MidiFileProperties();
                TrackReader        reader        = new TrackReader();
                List <Track>       newTracks     = new List <Track>();

                newProperties.Read(fileStream);

                for (int i = 0; i < newProperties.TrackCount; i++)
                {
                    reader.Read(fileStream);
                    newTracks.Add(reader.Track);
                }

                properties = newProperties;
                tracks     = newTracks;
            }

            #region Ensure

            Debug.Assert(Count == properties.TrackCount);

            #endregion
        }
        public void Load(MemoryStream ms)
        {
            ms.Seek(0, SeekOrigin.Begin);

            var newProperties = new MidiFileProperties();
            var reader        = new TrackReader();
            var newTracks     = new List <Track>();

            newProperties.Read(ms);

            for (int i = 0; i < newProperties.TrackCount; i++)
            {
                reader.Read(ms);
                reader.Track.Sequence = this;
                reader.Track.FileType = this.FileType;
                newTracks.Add(reader.Track);
            }

            properties = newProperties;
            tracks     = newTracks;
        }
Beispiel #5
0
        private void LoadDoWork(object sender, DoWorkEventArgs e)
        {
            string fileName = (string)e.Argument;

            FileStream stream = new FileStream(fileName, FileMode.Open,
                                               FileAccess.Read, FileShare.Read);

            using (stream)
            {
                MidiFileProperties newProperties = new MidiFileProperties();
                TrackReader        reader        = new TrackReader();
                List <Track>       newTracks     = new List <Track>();

                newProperties.Read(stream);

                float percentage;

                for (int i = 0; i < newProperties.TrackCount && !loadWorker.CancellationPending; i++)
                {
                    reader.Read(stream);
                    newTracks.Add(reader.Track);

                    percentage = (i + 1f) / newProperties.TrackCount;

                    loadWorker.ReportProgress((int)(100 * percentage));
                }

                if (loadWorker.CancellationPending)
                {
                    e.Cancel = true;
                }
                else
                {
                    properties = newProperties;
                    tracks     = newTracks;
                }
            }
        }