public PlaylistWindow(
            Playlist?playlist = null,
            IEnumerable <PlaylistTrack>?additionalPlaylistTracks = null,
            Action?refreshOwner = null)
        {
            this.playlist     = playlist;
            this.refreshOwner = refreshOwner;

            InitializeComponent();

            Width  = SystemParameters.PrimaryScreenWidth * .8;
            Height = SystemParameters.PrimaryScreenHeight * .8;

            Loaded  += playlistWindow_Loaded;
            Closing += PlaylistWindow_Closing;
            Closed  += playlistWindow_Closed;

            //tracks
            tracks    = new();
            trackRows = new();
            var trackNo = 0;

            totalDuration = TimeSpan.Zero;
            locations     = new();
            albums        = new();
            artists       = new();
            genres        = new();
            years         = new();

            if (playlist is not null)
            {
                //there is usually a playlist, except when VS tries to display PlaylistWindow
                PlaylistNameTextBox.Text = playlist.Name;
                foreach (var playlistTrack in playlist.PlaylistTracks.GetStoredItems().OrderBy(plt => plt.TrackNo))
                {
                    tracks.Add(playlistTrack.Track);
                    var isAdditionalTrack = additionalPlaylistTracks?.Contains(playlistTrack) ?? false;
                    var trackRow          = new TrackRow(ref trackNo, playlistTrack, updateSelectedCountTextBox, isAdditionalTrack);
                    trackRows.Add(trackRow);
                    if (isAdditionalTrack && firstAddedTrackRow is null)
                    {
                        firstAddedTrackRow = trackRow;
                    }
                }
                DurationTextBox.Text = playlist.TracksDurationHhMm;
                DC.GetTracksStats(ref totalDuration, locations, albums, artists, genres, years, tracks);
            }

            PlaylistNameTextBox.TextChanged += playlistNameTextBox_TextChanged;
            TracksCountTextBox.Text          = tracks.Count.ToString();

            //filter
            FilterTextBox.TextChanged          += filterTextBox_TextChanged;
            ArtistComboBox.SelectionChanged    += filterComboBox_SelectionChanged;
            ArtistComboBox.ItemsSource          = artists;
            AlbumComboBox.SelectionChanged     += filterComboBox_SelectionChanged;
            AlbumComboBox.ItemsSource           = albums;
            AlbumComboBox.DisplayMemberPath     = "AlbumArtist";
            GenreComboBox.SelectionChanged     += filterComboBox_SelectionChanged;
            GenreComboBox.ItemsSource           = genres;
            YearComboBox.SelectionChanged      += yearComboBox_SelectionChanged;
            YearComboBox.ItemsSource            = years;
            LocationsComboBox.SelectionChanged += filterComboBox_SelectionChanged;
            LocationsComboBox.ItemsSource       = locations;
            RemoveCheckBox.Click      += checkBox_Click;
            PlaylistCheckBox.Click    += checkBox_Click;
            ClearButton.Click         += clearButton_Click;
            RemoveAllButton.Click     += removeAllButton_Click;
            PLAllButton.Click         += plAllButton_Click;
            UnselectAllButton.Click   += unselectAllButton_Click;
            ExecuteRemoveButton.Click += executeRemoveButton_Click;
            AddToOtherPlaylistComboBox.ItemsSource = DC.Data.PlaylistStrings.Where(pls => pls != PlaylistNameTextBox.Text);
            AddToOtherPlaylistButton.Click        += addToOtherPlaylistButton_Click;

            //datagrid
            tracksViewSource        = ((System.Windows.Data.CollectionViewSource) this.FindResource("TracksViewSource"));
            tracksViewSource.Source = trackRows;
            tracksViewSource.IsLiveSortingRequested = true;
            tracksViewSource.Filter += tracksViewSource_Filter;
            //strangely, it seems both following lines are needed to make sorting work properly
            TracksDataGrid.Columns[0].SortDirection = ListSortDirection.Ascending;
            tracksViewSource.View.SortDescriptions.Add(new SortDescription("PlaylistTrackNo", ListSortDirection.Ascending));
            TracksDataGrid.Sorting          += tracksDataGrid_Sorting;
            TracksDataGrid.SelectionChanged += tracksDataGrid_SelectionChanged;
            TracksDataGrid.LayoutUpdated    += TracksDataGrid_LayoutUpdated;
            BeginningButton.Click           += beginningButton_Click;
            UpPageButton.Click   += upPageButton_Click;
            UpRowButton.Click    += upRowButton_Click;
            DownRowButton.Click  += downRowButton_Click;
            DownPageButton.Click += downPageButton_Click;
            EndButton.Click      += endButton_Click;
            SaveButton.Click     += saveButton_Click;
            SaveButton.IsEnabled  = false;

            //Replaced: TracksDataGrid.MouseDoubleClick += tracksDataGrid_MouseDoubleClick;
            //Style rowStyle = new Style(typeof(DataGridRow));
            //rowStyle.Setters.Add(new EventSetter(DataGridRow.MouseDoubleClickEvent,
            //                         new MouseButtonEventHandler(tracksDataGrid_MouseDoubleClick)));
            //TracksDataGrid.RowStyle = rowStyle;
            TracksDataGrid.RowStyle.Setters.Add(new EventSetter(DataGridRow.MouseDoubleClickEvent,
                                                                new MouseButtonEventHandler(tracksDataGrid_MouseDoubleClick)));

            TrackPlayer.TrackChanged += trackPlayer_TrackChanged;
            TrackPlayer.Init(getPlayinglist);

            MainWindow.Register(this, "Playlist " + playlist?.Name);
        }
Example #2
0
 public void addTrackRow(TrackRow trackRow)
 {
     this.TrackRows.Add(trackRow);
 }
Example #3
0
    public static void loadMidi(TextAsset midiText)
    {
        string[,] midiData;		//Parsed Midi Data

        int format;				//0 = single track. 1 = multi track
        int tracks;				//number of tracks, should be 1
        int tempo = 0;			//track tempo.
        int beatsPerBar = 0;
        int bpm;
        int ppq;

        int currentClock;
        int currentChannel;
        int currentInstrumentCode;
        int currentVelocity;
        float currentMs;
        string currentCommand;

        //Load Data file
        midiData = CSVReader.SplitCsvGrid (midiText.text);
        ppq = System.Int32.Parse(midiData [5, 0]);

        //Empty current track to prepare for loading
        CurrentTrack = new Track();

        CurrentTrack.TrackName = midiText.name;

        //Load the Midi into the Track row by row;
        for (int x = 0; x < midiData.GetLength(1); x += 1) {

            if (!System.Int32.TryParse(midiData[1,x], out currentClock))
            {
                break;
            }

            currentCommand = midiData[2,x].Trim ();

            //Get the channel/instrument info only when we have instructions to play a note
            if(currentCommand == "Note_on_c"){
                currentChannel = System.Int32.Parse(midiData[3,x]);
            }else{
                currentChannel = -1;
            }

            //Update tempo only once
            if(currentCommand == "Tempo" && tempo == 0){
                tempo = System.Int32.Parse(midiData[3,x]);
            }

            //Update Time Signature only once
            if(currentCommand == "Time_signature" && beatsPerBar == 0){
                beatsPerBar = System.Int32.Parse(midiData[3,x]);
            }

            //Convert ticks to Milliseconds
            currentMs = tempo / 1000.0f / ppq * currentClock;

            if(currentChannel == 9){

                currentInstrumentCode = System.Int32.Parse(midiData[4,x]);
                currentVelocity = System.Int32.Parse(midiData[5,x]);

                if(currentVelocity !=0){
                    TrackRow trackRow = new TrackRow (currentMs, DrumKit.getInstrumentFromMidiCode(currentInstrumentCode));

                    CurrentTrack.addTrackRow(trackRow);

                }
            }
        }

        bpm = (int) 60000000.0f / tempo;

        CurrentTrack.bpm = bpm;
        CurrentTrack.beatsPerBar = beatsPerBar;
    }
Example #4
0
 public static void recordBeat(DrumKit.Instrument instrument)
 {
     float timeSinceStart = (Time.time - recordingStartTime) * 1000; //Calculate time since start, in MS
     TrackRow trackRow = new TrackRow (timeSinceStart, instrument);
     CurrentTrack.addTrackRow(trackRow);
 }