public static void AddSongNoteToSong(double noteTime, Song song, Note xmlNote, double duration) { var songNote = new SongNote(); songNote.NoteTime = noteTime; songNote.PitchId = GetPitchIdFromNote(xmlNote); songNote.Velocity = 100; songNote.Duration = duration; SongNoteEventCollections noteEventCollections; if (!song.TryGetValue(noteTime, out noteEventCollections)) { noteEventCollections = new SongNoteEventCollections(); song.Add(noteTime, noteEventCollections); }; noteEventCollections.KeyPresses.Add(songNote); }
private void HandleClockTick(object sender, EventArgs e) { int ticks; lock (_lockObject) { ticks = _clock.Ticks; } if (ticks >= _nextNoteTick) { double noteTime = 0; double nextNoteTime = 0; //Get note list item noteTime = _songCopy.First().Key; SongNoteEventCollections noteEventList = _songCopy.First().Value; //Now drop it from the song _songCopy.Remove(_songCopy.First().Key); if (_songCopy.Any()) { nextNoteTime = _songCopy.First().Key; } else { nextNoteTime = 0; } //Handle key releases first foreach (SongNote note in noteEventList.KeyReleases) { _logger.Log(this, LogLevel.Debug, "Controller raising note release for: " + note.ToString()); SongNoteEvent(this, new SongEventArgs( new PianoKeyStrokeEventArgs(note.PitchId, KeyStrokeType.KeyRelease, note.Velocity), noteTime, nextNoteTime)); } //Handle key presses next foreach (SongNote note in noteEventList.KeyPresses) { _logger.Log(this, LogLevel.Debug, "Controller raising note press for: " + note.ToString()); SongNoteEvent(this, new SongEventArgs( new PianoKeyStrokeEventArgs(note.PitchId, KeyStrokeType.KeyPress, note.Velocity), noteTime, nextNoteTime)); } if (!_songCopy.Any()) { FinishSong(); } //New first item becomes next thing to watch for _nextNoteTick = ConvertNoteTimeToTick(_songCopy.Tempo, nextNoteTime); } }
private static Song BuildKeyReleases(Song song) { var songCopy = song.MakeCopy(); SongNoteEventCollections noteCollections; SongNoteEventCollections releaseNoteCollections; double releaseNoteTime; foreach(var noteTime in song.Keys) { noteCollections = songCopy[noteTime]; foreach (var note in noteCollections.KeyPresses) { releaseNoteTime = noteTime + note.Duration; //Now add release event at this time if (!songCopy.TryGetValue(releaseNoteTime, out releaseNoteCollections)) { releaseNoteCollections = new SongNoteEventCollections(); songCopy.Add(releaseNoteTime, releaseNoteCollections); }; releaseNoteCollections.KeyReleases.Add(note); } } return songCopy; }