Ejemplo n.º 1
0
        private void PlaybackTimer_Tick(object sender, EventArgs e)
        {
            MetricTimeSpan current  = currentPlayback.GetCurrentTime <MetricTimeSpan>();
            MetricTimeSpan duration = currentPlayback.GetDuration <MetricTimeSpan>();

            statusLabel.Text = $"Playing {Path.GetFileName(midiPath)} [{ToTimeString(current)} - {ToTimeString(duration)}]";
        }
Ejemplo n.º 2
0
        static string ChordToString(Chord chord, TempoMap tempoMap)
        {
            string representation = "\t\t{.music_notes = (struct MusicNote[]) {\n";

            //append each note to the chord
            int numNotes = 0;

            foreach (Note note in chord.Notes)
            {
                if (numNotes != 0)
                {
                    representation += ",\n";
                }
                representation += NoteToString(note, tempoMap);
                numNotes++;
            }

            representation += "\n\t\t}";

            //find the duration
            MetricTimeSpan chordDuration = LengthConverter.ConvertTo <MetricTimeSpan>(chord.Length, chord.Time, tempoMap);
            double         seconds       = chordDuration.TotalMicroseconds * MICROSECONDS_TO_SECONDS;

            representation += ", .duration = " + seconds + ", .num_notes = " + numNotes + "}";

            return(representation);
        }
Ejemplo n.º 3
0
        public void Chord_DefaultOctave()
        {
            var defaultVelocity = (SevenBitNumber)90;
            var defaultOctave   = 2;

            var chordLength = MusicalTimeSpan.Sixteenth.Triplet();
            var chordTime1  = new MetricTimeSpan(0, 1, 12);
            var chordTime2  = chordTime1.Add(chordLength, TimeSpanMode.TimeLength);

            var pattern = new PatternBuilder()
                          .SetVelocity(defaultVelocity)
                          .SetOctave(defaultOctave)

                          .MoveToTime(chordTime1)
                          .Chord(new[]
            {
                NoteName.C,
                NoteName.G
            }, chordLength)
                          .Repeat()

                          .Build();

            TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.C, defaultOctave, chordTime1, chordLength, defaultVelocity),
                new NoteInfo(NoteName.G, defaultOctave, chordTime1, chordLength, defaultVelocity),
                new NoteInfo(NoteName.C, defaultOctave, chordTime2, chordLength, defaultVelocity),
                new NoteInfo(NoteName.G, defaultOctave, chordTime2, chordLength, defaultVelocity)
            });
        }
Ejemplo n.º 4
0
        public void MoveToFirstSnapPoint_ByData_AtZero_CheckReturnValue()
        {
            var snapPoint1Time = new MetricTimeSpan(0, 0, 1);
            var snapPoint2Time = new MetricTimeSpan(0, 0, 0);
            var snapPoint3Time = new MetricTimeSpan(0, 0, 3);

            using (var playback = Get10SecondsPlayback())
            {
                var snapPoint1 = playback.Snapping.AddSnapPoint(snapPoint1Time, "X");
                var snapPoint2 = playback.Snapping.AddSnapPoint(snapPoint2Time, "Y");
                var snapPoint3 = playback.Snapping.AddSnapPoint(snapPoint3Time, "Z");

                Assert.IsTrue(playback.MoveToFirstSnapPoint("Y"), "Failed to move to first snap point.");
                CheckCurrentTime(playback, snapPoint2Time, "moved first time");

                Assert.IsTrue(playback.MoveToFirstSnapPoint("Y"), "Failed to move to first snap point again.");
                CheckCurrentTime(playback, snapPoint2Time, "moved second time");

                snapPoint2.IsEnabled = false;
                Assert.IsFalse(playback.MoveToFirstSnapPoint("Y"), "Moves to disabled snap point.");
                CheckCurrentTime(playback, snapPoint2Time, "moved third time");

                playback.MoveToTime(new MetricTimeSpan(0, 0, 5));
                Assert.IsTrue(playback.MoveToFirstSnapPoint("Z"), "Failed to move to first enabled snap point.");
                CheckCurrentTime(playback, snapPoint3Time, "moved fourth time");
            }
        }
Ejemplo n.º 5
0
    public void LoadSong(String songName)
    {
        // Load audio clip (from "Assets/Resources/Music")
        audioSource = GetComponent <AudioSource>();
        audioSource.Stop();
        audioSource.clip = Resources.Load <AudioClip>("Music/" + songName);

        // Load midi data (from "Assets/Resources/MusicData")
        notesInLanes = new List <List <GameNote> >();
        var midiFile = MidiFile.Read(Application.dataPath + "/Resources/MusicData/" + songName + ".mid");
        var tempoMap = midiFile.GetTempoMap();

        // Load midi data into note names and note hit times
        allNotes = new List <GameNote>();
        foreach (var note in midiFile.GetNotes())
        {
            NoteName       noteName       = note.NoteName;
            MetricTimeSpan metricTimeSpan = note.TimeAs <MetricTimeSpan>(tempoMap);
            allNotes.Add(new GameNote(noteName, timeInSeconds(metricTimeSpan)));
        }

        for (int i = 0; i < 4; i++)
        {
            List <GameNote> laneNotes = allNotes.Where(note => note.NoteName == laneNoteNames[i]).ToList();
            notesInLanes.Add(laneNotes);
        }

        sampleRate    = audioSource.clip.frequency;
        startingTempo = tempoMap.Tempo.AtTime(0);
    }
Ejemplo n.º 6
0
        private void btn_start_Click(object sender, EventArgs e)
        {
            IEnumerable <Note> notes    = midiObj.notes;
            TempoMap           tempoMap = midiObj.tempoMap;

            foreach (Note n in notes)
            {
                MetricTimeSpan metricTime = n.TimeAs <MetricTimeSpan>(tempoMap);

                NoteObj tmpNote =
                    new NoteObj(
                        new Point(
                            getNotePosition(n).X, 0), new MyTime(
                            metricTime.Minutes, metricTime.Seconds, metricTime.Milliseconds),
                        n.NoteName.ToString(),
                        getNoteWidth(n));
                listOfNotes.Add(tmpNote);
            }

            _minutes        = 0;
            _seconds        = 0;
            _miliseconds    = 0;
            hits            = 0;
            misses          = 0;
            lbl_hits.Text   = "Hits:  0";
            lbl_misses.Text = "Misses:  0";
            btn_openMidi.Hide();
            lbl_midiName.Hide();
            btn_start.Hide();
            enablePianoButtons();
            timerPiano.Start();
        }
Ejemplo n.º 7
0
        private static string CalcFactor(long noteAbsTime, TempoMap tempoMap)  //calculate the factor needed for presenting time in seconds
        {
            MetricTimeSpan metricTime  = TimeConverter.ConvertTo <MetricTimeSpan>(noteAbsTime, tempoMap);
            long           seconds     = 3600 * metricTime.Hours + 60 * metricTime.Minutes + metricTime.Seconds;
            long           miliSeconds = metricTime.Milliseconds;

            return($"{seconds}.{miliSeconds}");
        }
Ejemplo n.º 8
0
        private string ToTimeString(MetricTimeSpan time)
        {
            string seconds = time.Seconds.ToString();

            if (time.Seconds < 10)
            {
                seconds = seconds.Insert(0, "0");
            }

            return($"{time.Minutes}:{seconds}");
        }
Ejemplo n.º 9
0
    private void GetNotesAtTime(int currentTime, int seconds = 0, int miliseconds = 0)
    {
        IEnumerable <Note> notes = file.GetNotes().AtTime(new MetricTimeSpan(0, currentTime, seconds, miliseconds), tempoMap);

        foreach (Note note in notes)
        {
            MetricTimeSpan       metricTime    = note.TimeAs <MetricTimeSpan>(tempoMap);
            BarBeatTicksTimeSpan musicalTime   = note.TimeAs <BarBeatTicksTimeSpan>(tempoMap);
            MetricTimeSpan       musicalLength = note.LengthAs <MetricTimeSpan>(tempoMap);
            //Debug.Log("NOTE: " +note + " - NOTELENGTH: " + musicalLength);
        }
    }
Ejemplo n.º 10
0
        static string RestToString(MetricTimeSpan restDuration)
        {
            string representation = "\t\t{.music_notes = (struct MusicNote[]) {\n";

            double seconds = restDuration.TotalMicroseconds * MICROSECONDS_TO_SECONDS;

            representation += "\t\t\t{.note = \"S\", .octave = 0, .duration = " + seconds + ", .peak_intensity = 0, .sustain_intensity = 0, .adsr_envelope = (double[]) {0, 0, 0, 0}}\n";

            representation += "\t\t}, .duration = " + seconds + ", .num_notes = 1}";

            return(representation);
        }
Ejemplo n.º 11
0
        public void SetNoteLength()
        {
            Assert.AreEqual(MusicalTimeSpan.Quarter, PatternBuilder.DefaultNoteLength, "Default note length is invalid.");

            var patternBuilder = new PatternBuilder();

            Assert.AreEqual(PatternBuilder.DefaultNoteLength, patternBuilder.NoteLength, "Invalid initial note length.");

            var noteLength = new MetricTimeSpan(0, 0, 20);

            patternBuilder.SetNoteLength(noteLength);
            Assert.AreEqual(noteLength, patternBuilder.NoteLength, "Invalid note length after change.");
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            var midiFile = MidiFile.Read(args[0]);

            var chords   = midiFile.GetChords();
            var tempoMap = midiFile.GetTempoMap();

            List <List <Chord> > tracks = SortChords(chords);

#if DEBUG
            //output some debug data if necessary

            foreach (List <Chord> track in tracks)
            {
                System.Console.WriteLine("--TRACK START--");

                MetricTimeSpan totalTrackTime = new MetricTimeSpan(0);
                foreach (Chord chord in track)
                {
                    MetricTimeSpan chordStartTime = TimeConverter.ConvertTo <MetricTimeSpan>(chord.Time, tempoMap);
                    MetricTimeSpan chordDuration  = LengthConverter.ConvertTo <MetricTimeSpan>(chord.Length, chord.Time, tempoMap);
                    MetricTimeSpan chordEndTime   = chordStartTime + chordDuration;

                    System.Console.WriteLine("start: " + chordStartTime + " end: " + chordEndTime);

                    totalTrackTime += chordDuration;
                }

                System.Console.WriteLine("--TRACK END--");
                System.Console.WriteLine("TIME ELAPSED: " + totalTrackTime + "\n\n");
            }
#else
            //translate the tracks into code readable by the synth
            string songRepresentation = "{.music_tracks = (struct MusicTrack[]) {\n";

            foreach (List <Chord> track in tracks)
            {
                songRepresentation += TrackToString(track, tempoMap);
                if (tracks[tracks.Count - 1] != track)
                {
                    songRepresentation += ",\n";
                }
            }

            songRepresentation += "\n}, .num_tracks = " + tracks.Count + "}";

            System.Console.Write(songRepresentation);
#endif
        }
Ejemplo n.º 13
0
        public void ShiftEvents_ValidFiles_Metric()
        {
            var distance = new MetricTimeSpan(0, 1, 0);

            foreach (var midiFile in TestFilesProvider.GetValidFiles())
            {
                midiFile.ShiftEvents(distance);

                var tempoMap = midiFile.GetTempoMap();

                Assert.IsTrue(midiFile.GetTimedEvents()
                              .Select(e => e.TimeAs <MetricTimeSpan>(tempoMap).CompareTo(distance))
                              .All(t => t >= 0),
                              "Some events are not shifted.");
            }
        }
Ejemplo n.º 14
0
    public float BeatsToSecs(float beat)
    {
        if (!_HasMidiFile())
        {
            return(0.0f);
        }

        float          frac       = beat % 1.0f;
        int            beats      = (int)beat;
        int            ticks      = (int)(frac * _TicksPerBeat());
        BeatTimeSpan   inputSpan  = new BeatTimeSpan(beats, ticks);
        MetricTimeSpan outputSpan = TimeConverter.ConvertTo <MetricTimeSpan>(inputSpan, _tempoMap);

        float secs = outputSpan.TotalMicroseconds / 1000000.0f;

        return(secs);
    }
Ejemplo n.º 15
0
        private void OpenMidiFile()
        {
            try
            {
                _dancerSong = new DancerSong();
                OpenFileDialog openFileDialog = new OpenFileDialog
                {
                    Filter           = "MIDI files (*.mid)|*.mid;",
                    InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
                };
                if (openFileDialog.ShowDialog() == true)
                {
                    SelectedNote     = null;
                    _dancerSong.Midi = MidiFile.Read(openFileDialog.FileName);
                    ParsedNotes      = _midiEventsTextParser.ParseFromMidFormat(_dancerSong.Midi);
                    channelId        = 0;
                    ChannelTitles    = _midiEventsTextParser.ChannelTitles;
                    PresentedNotes   = _midiEventsTextParser.NotesInChannel[0];
                    selectedNotes    = new ObservableCollection <Note>();
                    SplitByChannels();
                    SelectedChannel = "All channels";
                    TicksPerQuarterNoteTimeDivision td = playback.TempoMap.TimeDivision as TicksPerQuarterNoteTimeDivision;
                    if (td is null)
                    {
                        throw new NotSupportedException("Time division in this MIDI file is not supported by this application.");
                    }
                    MetricTimeSpan metricTime = TimeConverter.ConvertTo <MetricTimeSpan>(td.TicksPerQuarterNote, playback.TempoMap);
                    _dancerSong.ticksPerSecond = td.TicksPerQuarterNote * 1000 / (metricTime.Seconds * 1000 + metricTime.Milliseconds);

                    EventSystem.Publish <OnMidiLoadedMessage>(
                        new OnMidiLoadedMessage
                    {
                        midiChannels        = this.midiChannels,
                        playback            = this.playback,
                        midiChannelsTitles  = this.channelTitles,
                        ticksPerSecond      = _dancerSong.ticksPerSecond,
                        ticksPerquarterNote = td.TicksPerQuarterNote
                    });
                }
            }
            catch (NotSupportedException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 16
0
        static string NoteToString(Note note, TempoMap tempoMap)
        {
            string representation = "\t\t\t{";

            //find the note name
            string name = note.NoteName.ToString();

            //convert the sharp into notation that the synth recognizes
            if (name.Contains("Sharp"))
            {
                name = name[0] + "s";
            }

            representation += ".note = \"" + name + "\"";

            //find the note octave
            int octave = note.Octave;

            representation += ", .octave = " + octave;

            //find the note duration
            MetricTimeSpan noteDuration = LengthConverter.ConvertTo <MetricTimeSpan>(note.Length, note.Time, tempoMap);

            double seconds = noteDuration.TotalMicroseconds * MICROSECONDS_TO_SECONDS;

            representation += ", .duration = " + seconds;

            //find the note peak and sustain intensity
            double peakIntensity    = System.Math.Pow(INTENSITY_SENSITIVITY, note.Velocity);
            double sustainIntensity = peakIntensity * SUSTAINABILITY;

            representation += ", .peak_intensity = " + peakIntensity + ", .sustain_intensity = " + sustainIntensity;

            //find the adsr envelope
            double adPercent = AD_SLOPE * (System.Math.Abs(note.Velocity) - 127) + MIN_AD_PERCENT;
            double aPercent  = adPercent * AD_PROPORTION;
            double dPercent  = adPercent - aPercent;
            double rPercent  = R_SLOPE * (System.Math.Abs(note.Velocity) - 127) + MIN_R_PERCENT;
            double sPercent  = 1 - aPercent - dPercent - rPercent;

            representation += ", .adsr_envelope = (double[]) {" + aPercent + ", " + dPercent + ", " + sPercent + ", " + rPercent + "}";

            representation += "}";
            return(representation);
        }
Ejemplo n.º 17
0
    public float SecsToBeats(float secs)
    {
        if (!_HasMidiFile())
        {
            return(0.0f);
        }

        long microseconds = (long)(secs * 1000000.0f);

        MetricTimeSpan inputSpan  = new MetricTimeSpan(microseconds);
        BeatTimeSpan   outputSpan = TimeConverter.ConvertTo <BeatTimeSpan>(inputSpan, _tempoMap);


        float beats = (float)outputSpan.Beats;

        beats += ((float)outputSpan.Ticks / _TicksPerBeat());

        return(beats);
    }
Ejemplo n.º 18
0
        public void Run()
        {
            MidiFile           file     = MidiFile.Read(midiPath);
            IEnumerable <Note> notes    = file.GetNotes();
            TempoMap           tempoMap = file.GetTempoMap();

            foreach (var note in notes)
            {
                MetricTimeSpan metricTime   = note.TimeAs <MetricTimeSpan>(tempoMap);
                MetricTimeSpan metricLength = note.LengthAs <MetricTimeSpan>(tempoMap);
            }
            using (StreamWriter newTask = new StreamWriter(this.txtPath, false))
            {
                foreach (var note in notes)
                {
                    MetricTimeSpan metricTime   = note.TimeAs <MetricTimeSpan>(tempoMap);
                    MetricTimeSpan metricLength = note.LengthAs <MetricTimeSpan>(tempoMap);
                }
            }
        }
Ejemplo n.º 19
0
        public void MoveToFirstSnapPoint_AtZero_CheckReturnValue()
        {
            var snapPoint1Time = new MetricTimeSpan();
            var snapPoint2Time = new MetricTimeSpan(0, 0, 2);

            using (var playback = Get10SecondsPlayback())
            {
                var snapPoint1 = playback.Snapping.AddSnapPoint(snapPoint1Time);
                var snapPoint2 = playback.Snapping.AddSnapPoint(snapPoint2Time);

                Assert.IsTrue(playback.MoveToFirstSnapPoint(), "Failed to move to first snap point.");
                CheckCurrentTime(playback, snapPoint1Time, "moved first time");

                Assert.IsTrue(playback.MoveToFirstSnapPoint(), "Failed to move to first snap point again.");
                CheckCurrentTime(playback, snapPoint1Time, "moved second time");

                snapPoint1.IsEnabled = false;
                Assert.IsTrue(playback.MoveToFirstSnapPoint(), "Failed to move to first snap point after first one disabled.");
                CheckCurrentTime(playback, snapPoint2Time, "moved third time");
            }
        }
Ejemplo n.º 20
0
        public void MoveToFirstAnchor_Keyed_OneUnkeyedAndOneKeyed()
        {
            var anchorTime = new MetricTimeSpan(0, 0, 30);

            var pattern = new PatternBuilder()
                          .MoveToTime(new MetricTimeSpan(0, 0, 10))
                          .StepForward(new MetricTimeSpan(0, 0, 11))
                          .Anchor()
                          .MoveToTime(anchorTime)
                          .Anchor("Test")
                          .StepBack(new MetricTimeSpan(0, 0, 5))
                          .MoveToFirstAnchor("Test")

                          .Note(Octave.Get(0).A)

                          .Build();

            TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.A, 0, anchorTime, MusicalTimeSpan.Quarter)
            });
        }
Ejemplo n.º 21
0
        public void CreateTxt()
        {
            MidiFile           file     = MidiFile.Read(midiPath);
            IEnumerable <Note> notes    = file.GetNotes();
            TempoMap           tempoMap = file.GetTempoMap();

            foreach (var note in notes)
            {
                MetricTimeSpan metricTime   = note.TimeAs <MetricTimeSpan>(tempoMap);
                MetricTimeSpan metricLength = note.LengthAs <MetricTimeSpan>(tempoMap);
            }
            using (StreamWriter newTask = new StreamWriter(this.txtPath, false))
            {
                foreach (var note in notes)
                {
                    MetricTimeSpan metricTime   = note.TimeAs <MetricTimeSpan>(tempoMap);
                    MetricTimeSpan metricLength = note.LengthAs <MetricTimeSpan>(tempoMap);
                    var            name         = note.NoteName;
                    var            value        = note.NoteNumber;
                    newTask.WriteLine(metricTime + "," + metricLength + "," + name + "," + value);
                }
            }
        }
Ejemplo n.º 22
0
        public void MoveToFirstAnchor_Unkeyed_OneUnkeyed()
        {
            var moveTime   = new MetricTimeSpan(0, 0, 10);
            var step       = new MetricTimeSpan(0, 0, 11);
            var anchorTime = moveTime + step;

            var pattern = new PatternBuilder()
                          .MoveToTime(moveTime)
                          .StepForward(step)
                          .Anchor()
                          .MoveToTime(new MetricTimeSpan(0, 0, 30))
                          .StepBack(new MetricTimeSpan(0, 0, 5))
                          .MoveToFirstAnchor()

                          .Note(OctaveDefinition.Get(0).A)

                          .Build();

            TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.A, 0, anchorTime, MusicalTimeSpan.Quarter)
            });
        }
Ejemplo n.º 23
0
        public void Note_MixedLengthAndVelocity()
        {
            var defaultNoteLength = MusicalTimeSpan.Quarter;
            var defaultVelocity   = (SevenBitNumber)90;

            var specifiedLength   = new MetricTimeSpan(0, 0, 10);
            var specifiedVelocity = (SevenBitNumber)95;

            var pattern = new PatternBuilder()
                          .SetNoteLength(defaultNoteLength)
                          .SetVelocity(defaultVelocity)

                          .Note(Octave.Get(0).A)
                          .Note(Octave.Get(1).C, specifiedLength, specifiedVelocity)

                          .Build();

            TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.A, 0, null, defaultNoteLength, defaultVelocity),
                new NoteInfo(NoteName.C, 1, MusicalTimeSpan.Quarter, specifiedLength, specifiedVelocity)
            });
        }
Ejemplo n.º 24
0
        public void SplitByGrid_MultipleSteps_FromZero_Mixed()
        {
            var tempoMap = TempoMap.Default;

            var obj1 = ObjectMethods.Create(new MidiTimeSpan(), MusicalTimeSpan.Whole, tempoMap);
            var obj2 = ObjectMethods.Create(new MetricTimeSpan(0, 0, 0, 210), new BarBeatTicksTimeSpan(1, 1), tempoMap);

            var step1 = MusicalTimeSpan.ThirtySecond;
            var step2 = new MetricTimeSpan(0, 0, 1);

            SplitByGrid_MultipleSteps(
                inputObjects: new[] { obj1, obj2 },
                gridStart: (MidiTimeSpan)0,
                gridSteps: new ITimeSpan[] { step1, step2 },
                expectedParts: new Dictionary <TObject, IEnumerable <TimeAndLength> >
            {
                [obj1] = new[]
                {
                    new TimeAndLength(new MusicalTimeSpan(), step1),
                    new TimeAndLength(step1, step2),
                    new TimeAndLength(step1.Add(step2, TimeSpanMode.TimeLength), step1),
                    new TimeAndLength((2 * step1).Add(step2, TimeSpanMode.TimeLength),
                                      (MusicalTimeSpan.Whole - 2 * step1).Subtract(step2, TimeSpanMode.LengthLength))
                },
                [obj2] = new[]
                {
                    new TimeAndLength(new MetricTimeSpan(0, 0, 0, 210),
                                      step1.Add(step2, TimeSpanMode.TimeLength).Subtract(new MetricTimeSpan(0, 0, 0, 210), TimeSpanMode.LengthLength)),
                    new TimeAndLength(step1.Add(step2, TimeSpanMode.TimeLength), step1),
                    new TimeAndLength((2 * step1).Add(step2, TimeSpanMode.TimeLength), step2),
                    new TimeAndLength((2 * step1).Add(step2 + step2, TimeSpanMode.TimeLength), step1),
                    new TimeAndLength((3 * step1).Add(step2 + step2, TimeSpanMode.TimeLength),
                                      new MetricTimeSpan(0, 0, 0, 210).Add(new BarBeatTicksTimeSpan(1, 1), TimeSpanMode.TimeLength).Subtract((3 * step1).Add(step2 + step2, TimeSpanMode.TimeLength), TimeSpanMode.TimeTime)),
                }
            },
                tempoMap: tempoMap);
        }
Ejemplo n.º 25
0
        static string TrackToString(List <Chord> track, TempoMap tempoMap)
        {
            string representation = "\t{.music_chords = (struct MusicChord[]) {\n";

            int num_chords = track.Count;

            MetricTimeSpan lastChordEndTime = new MetricTimeSpan(0);

            foreach (Chord chord in track)
            {
                MetricTimeSpan chordStartTime = TimeConverter.ConvertTo <MetricTimeSpan>(chord.Time, tempoMap);
                MetricTimeSpan chordDuration  = LengthConverter.ConvertTo <MetricTimeSpan>(chord.Length, chord.Time, tempoMap);
                MetricTimeSpan chordEndTime   = chordStartTime + chordDuration;

                //pad the track if necessary with rests
                if (lastChordEndTime < chordStartTime)
                {
                    representation += RestToString(chordStartTime - lastChordEndTime) + ",\n";
                    num_chords++;
                }

                //add the chord's string representation
                representation += ChordToString(chord, tempoMap);
                if (track[track.Count - 1] != chord)
                {
                    representation += ",\n";
                }

                //record the end time for the next chord
                lastChordEndTime = chordEndTime;
            }

            representation += "\n\t}, .playback_type = PLAYBACK_MONO, .length = " + num_chords + "}";

            return(representation);
        }
Ejemplo n.º 26
0
        public void MoveToFirstAnchor_Unkeyed_OneUnkeyedAndOneKeyed()
        {
            var moveTime   = new MetricTimeSpan(0, 0, 10);
            var step       = new MetricTimeSpan(0, 0, 11);
            var anchorTime = moveTime + step;

            var pattern = new PatternBuilder()
                          .MoveToTime(moveTime)
                          .StepForward(step)
                          .Anchor()
                          .MoveToTime(new MetricTimeSpan(0, 0, 30))
                          .Anchor("Test")
                          .StepBack(new MetricTimeSpan(0, 0, 5))
                          .MoveToFirstAnchor()

                          .Note(Notes.A0)

                          .Build();

            PatternTestUtilities.TestNotes(pattern, new[]
            {
                new NoteInfo(NoteName.A, 0, anchorTime, MusicalTimeSpan.Quarter)
            });
        }
Ejemplo n.º 27
0
 private static float GetMetricTimeSpanTotal(MetricTimeSpan ts)
 {
     return((float)ts.TotalMicroseconds / 1000000f);
 }
Ejemplo n.º 28
0
 public void ParseMetricTimeSpan_Valid(string metricTimeSpanString, MetricTimeSpan expectedTimeSpan)
 {
     TimeSpanTestUtilities.Parse(metricTimeSpanString, expectedTimeSpan);
 }
Ejemplo n.º 29
0
 private static MidiTimeSpan GetDefaultMidiTimeSpan(MetricTimeSpan timeSpan)
 {
     return(new MidiTimeSpan((timeSpan.TotalMicroseconds * TimeSpanTestUtilities.TicksPerQuarterNote) / Tempo.Default.MicrosecondsPerQuarterNote));
 }
Ejemplo n.º 30
0
 private static string Format(MetricTimeSpan timeSpan)
 {
     return(timeSpan.Minutes + ":" + timeSpan.Seconds.ToString("00"));
 }