Esempio n. 1
0
        public static MidiTimeBase Create(MidiRelativeTimeBase timeBase, MidiTempo tempo)
        {
            Check.IfArgumentNull(timeBase, "timeBase");
            Check.IfArgumentNull(tempo, "tempo");
            Check.IfArgumentOutOfRange(tempo.MillisecondTempo, 0, int.MaxValue, "tempo.MillisecondTempo");

            var midiTimeBase = new MidiTimeBase();

            midiTimeBase.MillisecondResolution = tempo.MillisecondTempo / timeBase.PulsesPerQuarterNote;

            return(midiTimeBase);
        }
Esempio n. 2
0
        /// <summary>
        /// Factory method for Midi file compatible values.
        /// </summary>
        /// <param name="timeDivision">Must not be zero.</param>
        /// <param name="tempo">Can be zero.</param>
        /// <returns>Never returns null.</returns>
        public static MidiTimeBase Create(int timeDivision, int tempo)
        {
            Check.IfArgumentOutOfRange(timeDivision, short.MinValue, ushort.MaxValue, "timeDivision");
            if (timeDivision == 0)
            {
                throw new ArgumentException("The timeDivision value can not be zero.", "timeDivision");
            }

            var midiTimeBase = new MidiTimeBase();

            if (((short)timeDivision) < 0)
            {
                var fps    = SmpteTime.ToFrameRate(Math.Abs((sbyte)((timeDivision & 0xFF00) >> 8)));
                var frames = timeDivision & 0x00FF;

                midiTimeBase.SmpteTime = new SmpteTime(0, 0, 0, frames, fps);
            }
            else
            {
                midiTimeBase.MillisecondResolution = tempo / timeDivision;
            }

            return(midiTimeBase);
        }