private void BindingCurrentTrack(IEnumerable <Track> checkin) { CurrentTracks = checkin.Select(s => new ObsTrack { IsPlay = false, Track = s }).ToList(); NoCurrentTracksVisibility = !CurrentTracks.Any(); }
public void UpdateSeperationEventStatus() { //Log if conditions for seperation event are no longer met. foreach (var e in CurrentEvents.events) { if (e is SeperationEvent) { string tag0 = e.InvolvedTracks[0].Tag; string tag1 = e.InvolvedTracks[1].Tag; TrackData track0; TrackData track1; //get updated track data try { track0 = CurrentTracks.Find(x => x.Tag == tag0); track1 = CurrentTracks.Find(x => x.Tag == tag1); //if the updated track data no longer matches conditions for SeperationEvent, set the isRaise-attribute to false if (CheckForSeperationEventConditions(track0, track1) == false) { //Mark that seperation event is no longer active - It will now be removed at next "cleanUp" e.isRaised = false; } } catch { //Mark that seperation event is no longer active - It will now be removed at next "cleanUp" e.isRaised = false; } } } }
void Instance_PlayStateChanged(object sender, EventArgs e) { if (BackgroundAudioPlayer.Instance.Track != null) { var track = BackgroundAudioPlayer.Instance.Track; if (PivotIndex == 0) { var _a = CurrentTracks.FirstOrDefault(a => a.Track.Audio.Preview.Contains(track.Source.ToString())); foreach (var obsTrack in CurrentTracks) { obsTrack.IsPlay = false; if (_a != null && obsTrack.Track.Id == _a.Track.Id && BackgroundAudioPlayer.Instance.PlayerState != PlayState.Paused) { obsTrack.IsPlay = true; } } } else { var _a = GeneralTracks.FirstOrDefault(a => a.Track.Audio.Preview.Contains(track.Source.ToString())); foreach (var obsTrack in GeneralTracks) { obsTrack.IsPlay = false; if (_a != null && obsTrack.Track.Id == _a.Track.Id && BackgroundAudioPlayer.Instance.PlayerState != PlayState.Paused) { obsTrack.IsPlay = true; } } } } }
/// <summary> /// Updates the currently selected viewmodel /// </summary> private void UpdateSelectedViewModel() { if (_trackInfos != null) { var currentTrackLookup = CurrentTracks.ToLookup(t => t.Index); foreach (var trackViewModel in _trackInfos) { trackViewModel.IsSelected = currentTrackLookup.Contains(trackViewModel.Track.Index); } } }
private void Play(ObsTrack obj) { //List<AudioTrack> list = new List<AudioTrack>(); //if (PivotIndex == 0) //{ // list = // CurrentTracks.Select( // t => new AudioTrack(new Uri(obj.Track.Audio.Preview), obj.Track.Name, obj.Track.Artist.Name, obj.Track.Album, null)).ToList(); // AudioPlayer.currentTrackNumber= CurrentTracks.IndexOf(obj); //} //else //{ // list = // GeneralTracks.Select( // t => new AudioTrack(new Uri(obj.Track.Audio.Preview), obj.Track.Name, obj.Track.Artist.Name, obj.Track.Album, null)).ToList(); // AudioPlayer.currentTrackNumber = GeneralTracks.IndexOf(obj); //} var i = 0; var list = new List <Track>(); if (PivotIndex == 0) { list = CurrentTracks.Select( t => t.Track).ToList(); i = CurrentTracks.IndexOf(obj); } else { list = GeneralTracks.Select( t => t.Track).ToList(); i = GeneralTracks.IndexOf(obj); } using (var ifs = new IsolatedStorageFileStream("playlist.xml", FileMode.Create, IsolatedStorageFile.GetUserStoreForApplication())) { var ser = new DataContractJsonSerializer(list.GetType()); ser.WriteObject(ifs, list); } using (var ifs = new IsolatedStorageFileStream("track.xml", FileMode.Create, IsolatedStorageFile.GetUserStoreForApplication())) { var ser = new DataContractJsonSerializer(i.GetType()); ser.WriteObject(ifs, i); } //BackgroundAudioPlayer.Instance.Track = new AudioTrack(new Uri(obj.Track.Audio.Preview), obj.Track.Name, obj.Track.Artist.Name, obj.Track.Album, null); BackgroundAudioPlayer.Instance.Play(); }
public void AddToPlaylist(TrackDefinition trackDefinition) { if (Current == null) { MultipleAddToPlaylistAndPlay(new[] { trackDefinition }, 0); return; } Current.AddTrack(trackDefinition); _currentTracks.Source = Current.Tracks; CurrentTracks.Refresh(); OnPropertyChanged(nameof(CurrentTracks)); }
public static string buildTrack(string state) { if (state == "startTrack") { selectedStationForSource = CurrentStations.Find(i => i.Name == Homepage.namingTextBox.Text.Trim()); if (string.IsNullOrEmpty(Homepage.namingTextBox.Text.Trim())) { Homepage.ConsoleTextBox.Text = "Sorry! You have to pick a Station"; return(state); } if (selectedStationForSource == null) { Homepage.ConsoleTextBox.Text = "We couldn't find a Station named " + Homepage.namingTextBox.Text.Trim(); return(state); } Homepage.ConsoleTextBox.Text = "Alright, we have set the start of the track to " + Homepage.namingTextBox.Text.Trim() + " now, where do you want it to end?"; Homepage.namingTextBox.Text = null; return("endTrack"); } if (state == "endTrack") { Homepage.ConsoleTextBox.Text = "we made it to endTrack"; if (string.IsNullOrEmpty(Homepage.namingTextBox.Text.Trim())) { Homepage.ConsoleTextBox.Text = "Sorry! You have to pick a Station"; return(state); } var selectedStationforDestination = CurrentStations.Find(i => i.Name == Homepage.namingTextBox.Text.Trim()); if (selectedStationforDestination == null) { Homepage.ConsoleTextBox.Text = "We couldn't find a Station named " + Homepage.namingTextBox.Text.Trim(); return(state); } Homepage.ConsoleTextBox.Text = "You picked Station " + selectedStationforDestination.Name; Homepage.namingTextBox.Text = null; if (selectedStationforDestination == selectedStationForSource) { Homepage.ConsoleTextBox.Text = "Sorry, you can't make a looped track. Transaction cancelled."; Bank.CurrentMoney += Bank.costOfTrack; Bank.updateMoneyBox(); return(null); } Homepage.ConsoleTextBox.Text = "Alright, we have set the track for you!"; CurrentTracks.Add(new Track(selectedStationForSource, selectedStationforDestination)); state = null; Train.updateTrainInfoBox(); Station.updateStationInfoBox(); } return(state); }
public void AddTrack(TrackData trackData) { //Check if TrackData with given tag already exists. if (CurrentTracks.Exists(x => x.Tag == trackData.Tag)) { //Find index of existing data. int index = CurrentTracks.FindIndex(x => x.Tag == trackData.Tag); //replace existing data with new data. CurrentTracks[index] = trackData; } else { //Add trackData. CurrentTracks.Add(trackData); } }
private static void DrawTrackTrunkSelectionWindow() { if (CurrentTracks?.Any() == true) { ImGui.Separator(); if (ImGui.BeginChild("TrackTrunkSelection", new Vector2(-1, Math.Min(5, CurrentTracks.Count) * ImGui.GetFrameHeightWithSpacing()), false)) { for (var i = 0; i < CurrentTracks.Count; i++) { if (ImGui.Checkbox($"[{i + 1:00}] {CurrentTracks[i].Item2}", ref config.EnabledTracks[i])) { try { //var progress = currentPlayback.GetCurrentTime<MidiTimeSpan>(); //var wasplaying = IsPlaying; currentPlayback?.Dispose(); //if (wasplaying) //{ //} } catch (Exception e) { PluginLog.Error(e, "error when disposing current playback while changing track selection"); } finally { currentPlayback = null; } } if (ImGui.IsItemHovered()) { if (ImGui.IsMouseReleased(ImGuiMouseButton.Right)) { ImGui.SetClipboardText(CurrentTracks[i].Item2); } } ToolTip( "Track Selection. \r\nMidiBard will only perform tracks been selected, which is useful in ensemble.\r\nChange on this will interrupt ongoing performance." .Localize()); } ImGui.EndChild(); } } }
private void RefreshDisplay() { if (Current.Tracks.Count > 50) { _currentTracks.Source = !_shuffled?Current.Tracks.Skip(PlayOffset).Take(50) : ShuffledList.Skip(PlayOffset).Take(50); } else if (Current.Tracks.Count - PlayOffset < 50) { _currentTracks.Source = !_shuffled?Current.Tracks.Skip(Math.Max(0, Current.Tracks.Count - 50)) : ShuffledList.Skip(Math.Max(0, Current.Tracks.Count - 50)); } else { _currentTracks.Source = !_shuffled ? (IEnumerable <Playlist.Member>)Current.Tracks : ShuffledList; } CurrentTracks.Refresh(); OnPropertyChanged(nameof(CurrentTracks)); }
public void UpdateTrackData(TrackData trackData) { // Update trackdata TrackData trackToEdit = CurrentTracks.Find(x => x.Tag == trackData.Tag); trackToEdit.CurrentHorzVel = CalculateTrackSpeed(trackData, trackToEdit); trackToEdit.CurrentCourse = CalculateTrackCourse(trackData, trackToEdit); trackToEdit.CurrentXcord = trackData.CurrentXcord; trackToEdit.CurrentYcord = trackData.CurrentYcord; trackToEdit.CurrentZcord = trackData.CurrentZcord; trackToEdit.CurrentHorzVel = trackToEdit.CurrentHorzVel; trackToEdit.TimeStamp = trackData.TimeStamp; //Replace old object with new object int index = CurrentTracks.FindIndex(x => x.Tag == trackData.Tag); CurrentTracks.RemoveAt(index); CurrentTracks.Insert(index, trackToEdit); }
public void MultipleAddToPlaylist(IEnumerable <TrackDefinition> tracks) { if (Current == null) { MultipleAddToPlaylistAndPlay(tracks, 0); return; } foreach (var track in tracks) { Current.AddTrack(track); } _currentTracks.Source = Current.Tracks; _shuffledList = null; if (_shuffled) { PlayOffset = ShuffledList.FindIndex(member => member.Position == Current.Tracks[PlayOffset].Position); } CurrentTracks.Refresh(); OnPropertyChanged(nameof(CurrentTracks)); }
public void HandleNewTrackData(TrackData trackdata) { //Check if no track data with given tag exists. if (CurrentTracks.Exists(x => x.Tag == trackdata.Tag) == false) { // Add the new track if coordinates are inside the given boundaries of the airspace. if (_airspace.CheckIfInMonitoredArea(trackdata.CurrentXcord, trackdata.CurrentYcord, trackdata.CurrentZcord)) { AddTrack(trackdata); //string time = trackdata._TimeStamp; //TrackEnteredEvent TrackEnteredEvent = new TrackEnteredEvent(time, trackdata, true, _outputConsole, _outputFile); CurrentEvents.AddTrackEnteredEventFor(trackdata, _outputFile); } } else { //Update trackdata UpdateTrackData(trackdata); // Remove tracks if out of airspace CheckIfTrackdataIsStillInAirspace(trackdata); // Check for potential seperation events CheckForSeperationEvents(trackdata); } //Remove all events that are not relevant anymore CurrentEvents.cleanUpEvents(); // Check for potential seperation events CheckForSeperationEvents(trackdata); // Update status of flightEvents' _isRaised-attribute. UpdateSeperationEventStatus(); }
public static Playback GetFilePlayback(this(MidiFile, string) fileTuple) { var file = fileTuple.Item1; MidiClockSettings clock = new MidiClockSettings { CreateTickGeneratorCallback = () => new HighPrecisionTickGenerator() }; try { CurrentTMap = file.GetTempoMap(); } catch (Exception e) { PluginLog.Debug("error when getting tmap, using default tmap instead."); CurrentTMap = TempoMap.Default; } Playback playback; try { CurrentTracks = file.GetTrackChunks() .Where(i => i.GetNotes().Any()) .Select(i => { var TrackName = string.Join(", ", i.Events.OfType <SequenceTrackNameEvent>().Select(j => j.Text.Replace("\0", string.Empty).Trim())); //var ProgramChangeEvent = string.Join(", ", i.Events.OfType<ProgramChangeEvent>().Select(j => j.ToString())); if (string.IsNullOrWhiteSpace(TrackName)) { TrackName = "Untitled"; } //var EventTypes = string.Join(", ", i.Events.GroupBy(j => j.EventType).Select(j => j.Key)); //var instrumentsName = string.Join(", ", i.Events.OfType<InstrumentNameEvent>().Select(j => j)); //try //{ var notes = i.GetNotes().ToList(); var notesCount = notes.Count; var notesHighest = notes.MaxElement(j => (int)j.NoteNumber).ToString(); var notesLowest = notes.MinElement(j => (int)j.NoteNumber).ToString(); //TrackName = "Note Track " + TrackName; var duration = TimeSpan.FromTicks(i.GetPlayback(CurrentTMap).GetDuration <MetricTimeSpan>().TotalMicroseconds * 10); //return (i, $"{TrackName} / {notesCount} notes / {notesLowest}-{notesHighest} / {(int)duration.TotalMinutes:00}:{duration.Seconds:00}.{duration.Milliseconds:000}"); return(i, $"{TrackName} / {notesCount} notes / {notesLowest}-{notesHighest}"); //} //catch (Exception e) //{ // var eventsCount = i.Events.Count; // var events = string.Join("\n", i.Events.Select(j => j.ToString().Replace("\0", string.Empty).Trim())); // var eventTypes = string.Join("", i.Events.GroupBy(j => j.EventType).Select(j => $"\n[{j.Key} {j.Count()}]")); // TrackName = "Control Track " + TrackName; // return (i, $"{TrackName} / {eventsCount} events{eventTypes}\n{file.GetDuration<MetricTimeSpan>()} / {i.GetPlayback(CurrentTMap).GetDuration<MetricTimeSpan>()}"); //} }).ToList(); List <TrackChunk> SelectedTracks = new List <TrackChunk>(); if (CurrentTracks.Count > 1) { for (int i = 0; i < CurrentTracks.Count; i++) { if (config.EnabledTracks[i]) { SelectedTracks.Add(CurrentTracks[i].Item1); } } } else { SelectedTracks = CurrentTracks.Select(i => i.Item1).ToList(); } playback = SelectedTracks.GetPlayback(CurrentTMap, BardPlayer, clock); } catch (Exception e) { PluginLog.Debug("error when parsing tracks, falling back to generated MidiEvent playback."); try { PluginLog.Debug($"file.Chunks.Count {file.Chunks.Count}"); var trackChunks = file.GetTrackChunks().ToList(); PluginLog.Debug($"file.GetTrackChunks.Count {trackChunks.Count()}"); PluginLog.Debug($"file.GetTrackChunks.First {trackChunks.First()}"); PluginLog.Debug($"file.GetTrackChunks.Events.Count {trackChunks.First().Events.Count()}"); PluginLog.Debug($"file.GetTrackChunks.Events.OfType<NoteEvent>.Count {trackChunks.First().Events.OfType<NoteEvent>().Count()}"); CurrentTracks = trackChunks.Select(i => { var notes = i.Events.OfType <NoteEvent>().GetNotes().ToList(); var notesCount = notes.Count; var notesHighest = notes.MaxElement(j => (int)j.NoteNumber).ToString(); var notesLowest = notes.MinElement(j => (int)j.NoteNumber).ToString(); var s = $"Reconstructed / {notesCount} notes / {notesLowest}-{notesHighest}"; return(new TrackChunk(i.Events.OfType <NoteEvent>()), s); }).ToList(); List <TrackChunk> SelectedTracks = new List <TrackChunk>(); for (int i = 0; i < CurrentTracks.Count; i++) { if (config.EnabledTracks[i]) { SelectedTracks.Add(CurrentTracks[i].Item1); } } playback = SelectedTracks.GetPlayback(CurrentTMap, BardPlayer, clock); } catch (Exception exception) { PluginLog.Error(e, "still errors? check your file"); throw; } } playback.InterruptNotesOnStop = true; playback.Speed = config.playSpeed; playback.Finished += Playback_Finished; return(playback); }
public static string moveTrain(string state) { if (state == "MoveTrain") { if (string.IsNullOrEmpty(Homepage.namingTextBox.Text.Trim())) { Homepage.ConsoleTextBox.Text = "Sorry! You have to pick a Train"; return(state); } TrainForMove = CurrentTrains.Find(i => i.Name == Homepage.namingTextBox.Text.Trim()); if (TrainForMove == null) { Homepage.ConsoleTextBox.Text = "We couldn't find a train named " + Homepage.namingTextBox.Text.Trim(); return(null); } Homepage.namingTextBox.Text = null; Homepage.ConsoleTextBox.Text = "Alright, we found your Train! It is at station " + TrainForMove.TrainCurrentLocation.Name + " .Go ahead and add any packages or press 'Yes' to continue."; state = "PackageManagement"; foreach (Package i in TrainForMove.TrainCurrentLocation.PackagesWaiting) { Homepage.packageSelectionDropDown.Items.Add(i.PackageType + "-" + i.PackageValue + "," + i.PackageDestinationStation.Name); } return(state); } else if (state == "MoveTrainDestination") { if (string.IsNullOrEmpty(Homepage.namingTextBox.Text.Trim())) { Homepage.ConsoleTextBox.Text += "Sorry! You have to pick a Station"; return(state); } var selectedStationForMoving = CurrentStations.Find(i => i.Name == Homepage.namingTextBox.Text.Trim()); if (selectedStationForMoving == null) { Homepage.ConsoleTextBox.Text = "We couldn't find a Station named " + Homepage.namingTextBox.Text.Trim(); return(state); } var trackExists = CurrentTracks.Find(i => i.sourceStation == TrainForMove.TrainCurrentLocation && i.destinationStation == selectedStationForMoving); if (trackExists == null) { Homepage.ConsoleTextBox.Text = "Sorry, there is no track there. Transaction cancelled."; Homepage.namingTextBox.Text = null; return(null); } TrainForMove.TrainCurrentLocation = selectedStationForMoving; Homepage.ConsoleTextBox.Text = "You have moved!"; Homepage.namingTextBox.Text = null; Train.updateTrainInfoBox(); Station.updateStationInfoBox(); Homepage.packageSelectionDropDown.Items.Clear(); Homepage.packageSelectionDropDown.SelectedItem = null; foreach (Package i in TrainForMove.Holding) { if (i.PackageDestinationStation == TrainForMove.TrainCurrentLocation) { Bank.CurrentMoney += i.PackageValue; Homepage.ConsoleTextBox.Text = "Awesome! Packages have been successfully delivered!"; } } TrainForMove.Holding.RemoveAll(i => i.PackageDestinationStation == TrainForMove.TrainCurrentLocation); Bank.updateMoneyBox(); Train.updateTrainInfoBox(); Station.updateStationInfoBox(); state = null; } return(state); }
public void RemoveTrack(string tag) { int index = CurrentTracks.FindIndex(x => x.Tag.Equals(tag)); CurrentTracks.RemoveAt(index); }
private static unsafe void DrawTrackTrunkSelectionWindow() { if (CurrentTracks?.Any() == true) { ImGui.Separator(); ImGui.PushStyleColor(ImGuiCol.Separator, 0); //ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(-10,-10)); //ImGui.PushStyleVar(ImGuiStyleVar.CellPadding, new Vector2(-10, -10)); //ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(-10, -10)); if (ImGui.BeginChild("TrackTrunkSelection", new Vector2(ImGui.GetWindowWidth(), Math.Min(CurrentTracks.Count, 6.6f) * ImGui.GetFrameHeightWithSpacing() - ImGui.GetStyle().ItemSpacing.Y), false, ImGuiWindowFlags.NoDecoration)) { ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 2f); ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(2, ImGui.GetStyle().ItemSpacing.Y)); ImGui.PushStyleVar(ImGuiStyleVar.ButtonTextAlign, new Vector2(0.6f, 0)); if (PlayingGuitar && config.OverrideGuitarTones) { ImGui.Columns(2); ImGui.SetColumnWidth(0, ImGui.GetWindowContentRegionWidth() - 4 * ImGui.GetCursorPosX() - ImGui.GetFontSize() * 5.5f - 10); } for (var i = 0; i < CurrentTracks.Count; i++) { ImGui.SetCursorPosX(0); var configEnabledTrack = !config.EnabledTracks[i]; if (configEnabledTrack) { ImGui.PushStyleColor(ImGuiCol.Text, *ImGui.GetStyleColorVec4(ImGuiCol.TextDisabled)); } if (ImGui.Checkbox($"[{i + 1:00}] {CurrentTracks[i].Item2}", ref config.EnabledTracks[i])) { //try //{ // //var progress = currentPlayback.GetCurrentTime<MidiTimeSpan>(); // //var wasplaying = IsPlaying; // currentPlayback?.Dispose(); // //if (wasplaying) // //{ // //} //} //catch (Exception e) //{ // PluginLog.Error(e, "error when disposing current playback while changing track selection"); //} //finally //{ // currentPlayback = null; //} } if (configEnabledTrack) { ImGui.PopStyleColor(); } if (ImGui.IsItemHovered()) { if (ImGui.IsMouseReleased(ImGuiMouseButton.Right)) { ImGui.SetClipboardText(CurrentTracks[i].Item2.ToString()); } ImGui.BeginTooltip(); ImGui.TextUnformatted(CurrentTracks[i].Item2.ToLongString()); ImGui.EndTooltip(); } //ToolTip(CurrentTracks[i].Item2.ToLongString() // //+ "\n" + // //("Track Selection. MidiBard will only perform tracks been selected, which is useful in ensemble.\r\nChange on this will interrupt ongoing performance." // // .Localize()) // ); if (PlayingGuitar && config.OverrideGuitarTones) { ImGui.NextColumn(); var width = ImGui.GetWindowContentRegionWidth(); //var spacing = ImGui.GetStyle().ItemSpacing.X; var buttonSize = new Vector2(ImGui.GetFontSize() * 1.1f, ImGui.GetFrameHeight()); const uint colorRed = 0xee_6666bb; const uint colorCyan = 0xee_bbbb66; const uint colorGreen = 0xee_66bb66; const uint colorYellow = 0xee_66bbbb; const uint colorBlue = 0xee_bb6666; void drawButton(int toneID, uint color, string toneName, int track) { //ImGui.SameLine(width - (4.85f - toneID) * 3 * spacing); var DrawColor = config.TracksTone[track] == toneID; if (DrawColor) { ImGui.PushStyleColor(ImGuiCol.Button, color); ImGui.PushStyleColor(ImGuiCol.ButtonHovered, color); ImGui.PushStyleColor(ImGuiCol.ButtonActive, color); } if (ImGui.Button($"{toneName}##toneSwitchButton{i}", buttonSize)) { config.TracksTone[track] = toneID; } if (DrawColor) { ImGui.PopStyleColor(3); } } drawButton(0, colorRed, " I ", i); ImGui.SameLine(); drawButton(1, colorCyan, " II ", i); ImGui.SameLine(); drawButton(2, colorGreen, "III", i); ImGui.SameLine(); drawButton(3, colorYellow, "IV", i); ImGui.SameLine(); drawButton(4, colorBlue, "V", i); ImGui.NextColumn(); } } ImGui.PopStyleVar(3); ImGui.EndChild(); } //ImGui.PopStyleVar(3); ImGui.PopStyleColor(); } }
public static BardPlayback GetFilePlayback(this(MidiFile, string) fileTuple) { var file = fileTuple.Item1; try { CurrentTMap = file.GetTempoMap(); } catch (Exception e) { PluginLog.Error("error when getting file TempoMap, using default TempoMap instead."); CurrentTMap = TempoMap.Default; } try { CurrentTracks = file.GetTrackChunks() .Where(i => i.GetNotes().Any()) .Select(i => { var notes = i.GetNotes().ToList(); var notesCount = notes.Count; var notesHighest = notes.MaxElement(j => (int)j.NoteNumber); var notesLowest = notes.MinElement(j => (int)j.NoteNumber); return(i, new TrackInfo { TrackNameEventsText = i.Events.OfType <SequenceTrackNameEvent>().Select(j => j.Text.Replace("\0", string.Empty).Trim()).Distinct(), TextEventsText = i.Events.OfType <TextEvent>().Select(j => j.Text.Replace("\0", string.Empty).Trim()).Distinct(), ProgramChangeEvent = i.Events.OfType <ProgramChangeEvent>().Select(j => $"channel {j.Channel}, {(GeneralMidiProgram)(byte)j.ProgramNumber}").Distinct(), HighestNote = notesHighest, LowestNote = notesLowest, NoteCount = notesCount, Duration = i.GetTimedEvents().LastOrDefault(e => e.Event is NoteOffEvent)?.TimeAs <MetricTimeSpan>(CurrentTMap) ?? new MetricTimeSpan() }); }).ToList(); } catch (Exception exception1) { PluginLog.Error($"error when parsing tracks, falling back to generated MidiEvent playback. \n{exception1}"); try { PluginLog.Debug($"file.Chunks.Count {file.Chunks.Count}"); var trackChunks = file.GetTrackChunks().ToList(); PluginLog.Debug($"file.GetTrackChunks.Count {trackChunks.Count}"); PluginLog.Debug($"file.GetTrackChunks.First {trackChunks.First()}"); PluginLog.Debug($"file.GetTrackChunks.Events.Count {trackChunks.First().Events.Count}"); PluginLog.Debug($"file.GetTrackChunks.Events.OfType<NoteEvent>.Count {trackChunks.First().Events.OfType<NoteEvent>().Count()}"); CurrentTracks = trackChunks.Select(i => { var notes = i.Events.OfType <NoteEvent>().GetNotes().ToList(); var notesCount = notes.Count; var notesHighest = notes.MaxElement(j => (int)j.NoteNumber); var notesLowest = notes.MinElement(j => (int)j.NoteNumber); var trackChunk = new TrackChunk(i.Events.OfType <NoteEvent>()); return(trackChunk, new TrackInfo { TrackNameEventsText = i.Events.OfType <SequenceTrackNameEvent>().Select(j => j.Text.Replace("\0", string.Empty).Trim()).Distinct(), TextEventsText = i.Events.OfType <TextEvent>().Select(j => j.Text.Replace("\0", string.Empty).Trim()).Distinct(), ProgramChangeEvent = i.Events.OfType <ProgramChangeEvent>().Select(j => $"{j.Channel} {(GeneralMidiProgram)(byte)j.ProgramNumber}").Distinct(), HighestNote = notesHighest, LowestNote = notesLowest, NoteCount = notesCount }); }).ToList(); } catch (Exception exception2) { PluginLog.Error(exception2, "still errors? check your file"); throw; } } //List<TrackChunk> SelectedTracks = new List<TrackChunk>(); //if (CurrentTracks.Count > 1) //{ // for (int i = 0; i < CurrentTracks.Count; i++) // { // if (config.EnabledTracks[i]) // { // SelectedTracks.Add(CurrentTracks[i].Item1); // } // } //} //else //{ // SelectedTracks = CurrentTracks.Select(i => i.Item1).ToList(); //} var timedEvents = CurrentTracks.Select(i => i.Item1) .SelectMany((chunk, index) => chunk.GetTimedEvents().Select(e => new TimedEventWithTrackChunkIndex(e.Event, e.Time, index))) .OrderBy(e => e.Time); var playback = new BardPlayback(timedEvents, CurrentTMap, clock) { InterruptNotesOnStop = true, Speed = config.playSpeed }; if (config.autoPitchShift) { var match = regex.Match(fileTuple.Item2); if (match.Success && int.TryParse(match.Groups[1].Value, out var demandedNoteOffset)) { PluginLog.Debug($"DemandedNoteOffset: {demandedNoteOffset}"); config.NoteNumberOffset = demandedNoteOffset; } else { //config.NoteNumberOffset = 0; } playback.Finished += (sender, args) => { switch ((PlayMode)config.PlayMode) { case PlayMode.Single: break; case PlayMode.SingleRepeat: break; case PlayMode.ListOrdered: if (match.Success) { config.NoteNumberOffset = 0; } break; case PlayMode.ListRepeat: if (match.Success) { config.NoteNumberOffset = 0; } break; case PlayMode.Random: if (match.Success) { config.NoteNumberOffset = 0; } break; default: throw new ArgumentOutOfRangeException(); } }; } playback.Finished += Playback_Finished; return(playback); }