Beispiel #1
0
        private void Algorithm_Unchecked(FileInfo[] trackArray, StartForm startForm, int numerTab, int i)
        {
            for (int j = memory[i]; j < trackArray.Length; j++)
            {
                startForm.Invoke((MethodInvoker)(() => startForm.TabPlaylist.TabPages[numerTab].Controls.OfType <System.Windows.Forms.TextBox>().First().Text += trackArray[j].FullName.ToString() + Environment.NewLine));

                try
                {
                    var audioFile = TagLib.File.Create(trackArray[j].FullName.ToString(), TagLib.ReadStyle.Average);
                    hours += audioFile.Properties.Duration;
                }
                catch (CorruptFileException)
                {
                    continue;
                    //todo: сделать запись в логи
                }

                if (hours >= duration)
                {
                    memory[i] = j + 1;

                    if (memory[i] == trackArray.Length)
                    {
                        memory[i] = 0;
                    }
                    break;
                }
                if (hours < duration && j == trackArray.Length - 1)
                {
                    memory[i] = 0;
                    Algorithm_Unchecked(trackArray, startForm, numerTab, i);
                }
            }
        }
Beispiel #2
0
        object block = new object();        // объект синхронизации

        #endregion

        public void GenConrol(StartForm startForm)
        {
            if (PlayGen.Properties.Settings.Default.ToOpenFolders)
            {
                GenConrol_24Hour_OpenFolder(startForm);
            }
            else
            {
                GenConrol_24Hour_CloseFolder(startForm);
            }
        }
Beispiel #3
0
        public void Clear(StartForm startForm)
        {
            boxControls.Clear();                                     //очищаем лист с элементами
            count       = 0;                                         // сброс подсчета элементов
            k           = 0;                                         //сброс счета валидных папок
            timeCount   = null;                                      //сброс времени
            progressing = 1;                                         //прогресс по умолчанию
            startForm.ProgressLabel.Text = "Ready";                  // сброс текста прогресса
            startForm.Panel.Controls.Clear();                        //очищаем панель

            for (int z = 0; z < startForm.TabPlaylist.TabCount; z++) // очистка плейлиста на форме
            {
                startForm.TabPlaylist.TabPages[z].Controls.OfType <System.Windows.Forms.TextBox>().First().Clear();
            }
            startForm.Panel.BackgroundImage = Properties.Resources.drag; // возвращаем фоновое изображение
        }
Beispiel #4
0
 public void GenTrackMode(StartForm startForm)
 {
     if (startForm.Mode == 0)
     {
         if (PlayGen.Properties.Settings.Default.ToOpenFolders)
         {
             GenTrack_24Hour_OpenFolder(startForm);
         }
         else
         {
             GenTrack_24Hour_CloseFolder(startForm);
         }
     }
     else
     {
         //GenTrack_Single();
         //todo: Сделать режим
     }
 }
Beispiel #5
0
 void Save(StartForm startForm)
 {
     SaveSettings();
     startForm.Clear();
     this.Close();
 }
Beispiel #6
0
 public Settings(StartForm startForm)
 {
     InitializeComponent();
     LoadSetting();
     form = startForm;
 }
Beispiel #7
0
        private void Algorithm_Unchecked_CloseFolder(DirectoryInfo[] dirArr, StartForm startForm, int numerTab, int i, int memoryIndex)
        {
            for (int z = memoryDir[memoryIndex]; z < dirArr.Length; z++) // пробегаемся по подпапкам корневой папки
            {
                string[] extensions = Settings.GetAudioFormat();

                FileInfo[] trackArray = dirArr[z].GetFiles("*.*", SearchOption.AllDirectories)
                                        .Where(f => extensions.Contains(f.Extension.ToLower()))
                                        .ToArray();

                if (trackArray.Length == 0)
                {
                    memoryDir[memoryIndex] = z + 1;

                    if (memoryDir[memoryIndex] == dirArr.Length)
                    {
                        memoryDir[memoryIndex] = 0;
                    }
                    Algorithm_Unchecked_CloseFolder(dirArr, startForm, numerTab, i, memoryIndex);
                }


                if (boxControls[i].TrackMix.Checked)
                {
                    trackArray = trackArray.OrderBy(x => rnd.Next()).ToArray();
                }

                for (int j = memory[i]; j < trackArray.Length; j++)
                {
                    startForm.Invoke((MethodInvoker)(() => startForm.TabPlaylist.TabPages[numerTab].Controls.OfType <System.Windows.Forms.TextBox>().First().Text += trackArray[j].FullName.ToString() + Environment.NewLine));

                    try
                    {
                        var audioFile = TagLib.File.Create(trackArray[j].FullName.ToString(), TagLib.ReadStyle.Average);
                        hours += audioFile.Properties.Duration;
                    }
                    catch (CorruptFileException)
                    {
                        continue;
                        //todo: сделать запись в логи
                    }

                    if (hours >= duration)
                    {
                        memory[i] = j + 1;
                        memoryDir[memoryIndex] = z;

                        if (memory[i] == trackArray.Length)
                        {
                            memory[i] = 0;
                            memoryDir[memoryIndex] = z + 1;
                        }

                        if (memoryDir[memoryIndex] == dirArr.Length)
                        {
                            memoryDir[memoryIndex] = 0;
                        }
                        return;
                    }

                    if (hours < duration && j == trackArray.Length - 1)
                    {
                        memory[i] = 0;
                        memoryDir[memoryIndex] = z + 1;

                        if (memoryDir[memoryIndex] == dirArr.Length)
                        {
                            memoryDir[memoryIndex] = 0;
                        }
                        Algorithm_Unchecked_CloseFolder(dirArr, startForm, numerTab, i, memoryIndex);
                    }
                }
            }
        }
Beispiel #8
0
        public void GenTrack_24Hour_CloseFolder(StartForm startForm)
        {
            memory    = new int[count]; // запоминаем место продолжения генерации трека
            memoryDir = new int[count]; // запоминаем папку

            progressing = 1;
            startForm.Invoke(new MethodInvoker(() => startForm.ProgressBar.Value = 0));

            //очищаем плейлист
            for (int z = 0; z < startForm.TabPlaylist.TabCount; z++)
            {
                startForm.TabPlaylist.Invoke(new MethodInvoker(() => startForm.TabPlaylist.TabPages[z].Controls.OfType <System.Windows.Forms.TextBox>().First().Clear()));
            }

            List <UIControl> tempBox = new List <UIControl>();               // временный лист

            if (startForm.BlockShuffle)                                      // блоковая генерация
            {
                tempBox.AddRange(boxControls);                               //добавляем контролы во временный лист
                boxControls = boxControls.OrderBy(x => rnd.Next()).ToList(); //перемешать контролы в боксконтролс
            }

            for (int z = 0; z < startForm.TabPlaylist.TabCount; z++) // пробегаемся по всем листам плейлиста
            {
                for (int i = 0; i < count; i++)                      // пробегаемся по контролам на панели
                {
                    if (boxControls[i].NumericHours.Value != 0 || boxControls[i].NumericMinutes.Value != 0)
                    {
                        DirectoryInfo pathInfo = new DirectoryInfo(boxControls[i].TextBoxFolder.Text); // получаем путь к корневой папке

                        DirectoryInfo[] dirArr = pathInfo.GetDirectories();                            // получаем поддиректории корневой папки

                        if (boxControls[i].DirectoryMix.Checked)
                        {
                            dirArr = dirArr.OrderBy(x => rnd.Next()).ToArray();
                        }

                        duration = new TimeSpan((int)boxControls[i].NumericHours.Value, (int)boxControls[i].NumericMinutes.Value, 0);
                        hours    = TimeSpan.Zero;

                        Algorithm_Unchecked_CloseFolder(dirArr, startForm, z, i, i); // алгоритм генерации
                    }
                }

                if (startForm.AllShuffle)
                {
                    List <string> split = new List <string>(startForm.TabPlaylist.TabPages[z].Controls.OfType <System.Windows.Forms.TextBox>().First().Text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));
                    startForm.Invoke((MethodInvoker)(() => startForm.TabPlaylist.TabPages[z].Controls.OfType <System.Windows.Forms.TextBox>().First().Clear()));

                    int count = split.Count; // количество треков для рандома

                    for (int i = 0; i < count; i++)
                    {
                        int randomNumber = rnd.Next(split.Count);
                        startForm.Invoke((MethodInvoker)(() => startForm.TabPlaylist.TabPages[z].Controls.OfType <System.Windows.Forms.TextBox>().First().Text += split[randomNumber] + "\r\n"));
                        split.RemoveAt(randomNumber);
                    }
                }

                startForm.Invoke(new MethodInvoker(() =>
                {
                    startForm.ProgressBar.Value  = (progressing * 100 / 7);
                    startForm.ProgressLabel.Text = startForm.ProgressBar.Value.ToString() + " %";
                    progressing++;
                }));
            }

            if (startForm.BlockShuffle)
            {
                boxControls = tempBox;
            }
        }
Beispiel #9
0
        void GenConrol_24Hour_OpenFolder(StartForm startForm)
        {
            startForm.Panel.BackgroundImage = null;

            progressing = 0;
            startForm.Invoke(new MethodInvoker(() => startForm.ProgressBar.Value = 0));

            DirectoryInfo[] dirArr = startForm.PathInfo.GetDirectories(); // получаю поддиректории

            if (dirArr.Length == 0)
            {
                startForm.Invoke(new MethodInvoker(() => startForm.ProgressBar.Value = 0));
                return;
            }

            int value = dirArr.Length; // количество поддиректорий

            lock (block)
            {
                for (int i = count; i < count + value; i++)
                {
                    startForm.Panel.Invoke(new MethodInvoker(() =>
                    {
                        uiControl = new UIControl();
                        uiControl.DirectoryMix.Visible = false;

                        //
                        // TextBox Folfer
                        //
                        uiControl.TextBoxFolder.Name = "textBox" + i.ToString();
                        uiControl.TextBoxFolder.Text = dirArr[i - count].FullName.ToString();

                        //
                        // NumericMinutes
                        //
                        uiControl.NumericMinutes.Name          = "numericMinutes" + i.ToString();
                        uiControl.NumericMinutes.Value         = 0;
                        uiControl.NumericMinutes.ValueChanged += Time_ValueChanged;
                        uiControl.NumericMinutes.Tag           = k;

                        //
                        // NumericHours
                        //
                        uiControl.NumericHours.Name          = "numericHours" + i.ToString();
                        uiControl.NumericHours.Value         = 0;
                        uiControl.NumericHours.ValueChanged += Time_ValueChanged;
                        uiControl.NumericHours.Tag           = k;

                        //
                        // CountLabel MaxDuration Tracks
                        //
                        uiControl.MaxTime.Name = "maxTimeLabel" + i.ToString();

                        DirectoryInfo pathInfo = new DirectoryInfo(uiControl.TextBoxFolder.Text);

                        // string[] extensions = new[] { ".mp3", ".wav", ".flac" };
                        string[] extensions = Settings.GetAudioFormat();

                        FileInfo[] trackArray = pathInfo.GetFiles("*.*", SearchOption.AllDirectories)
                                                .Where(f => extensions.Contains(f.Extension.ToLower()))
                                                .ToArray();

                        duration = TimeSpan.Zero;

                        for (int y = 0; y < trackArray.Length; y++)
                        {
                            try
                            {
                                var audioFile = TagLib.File.Create(trackArray[y].FullName.ToString(), TagLib.ReadStyle.Average);
                                duration     += audioFile.Properties.Duration;
                            }
                            catch (CorruptFileException)
                            {
                                continue;
                                //todo: сделать запись в логи
                            }

                            catch (PathTooLongException)
                            {
                                DialogResult result = MessageBox.Show("Фаил или директория\n\n" + trackArray[y].FullName.ToString() + "\n\n Имеет слишком длинный путь или имя файла. Полное имя файла должно содержать меньше 260 знаков, а имя каталога - меньше 248", "Ошибка! Пропустить?", MessageBoxButtons.YesNo);

                                if (result == DialogResult.Yes)
                                {
                                    y = trackArray.Length;
                                    i = count + value;
                                    startForm.ProgressBar.Value = 100;
                                    break;
                                }
                                else
                                {
                                    y = trackArray.Length;
                                    Application.Restart();
                                }
                            }
                        }
                        uiControl.MaxTime.Text      = "/" + duration.ToString("dd\\:hh\\:mm\\:ss");
                        uiControl.MaxTime.ForeColor = System.Drawing.Color.Red;

                        //
                        // ChekBox Shuffle Tracks
                        //
                        uiControl.TrackMix.Name = "innerShuffle" + i.ToString();

                        //
                        //ADDControls
                        //
                        if (uiControl.MaxTime.Text != "/00:00:00:00")
                        {
                            //
                            // NumberLabel
                            //
                            uiControl.NumerLabel.Name = "label" + i.ToString();
                            uiControl.NumerLabel.Text = (k + 1).ToString();
                            k++;

                            boxControls.Add(uiControl);
                            startForm.Panel.Controls.Add(uiControl);

                            progressing++;
                            startForm.ProgressBar.Value = (progressing * 100 / value);
                        }
                        else
                        {
                            progressing++;
                            startForm.ProgressBar.Value = (progressing * 100 / value);
                        }
                    }));
                }

                //
                // Label timeCount
                //
                if (timeCount == null)
                {
                    timeCount = startForm.TimeCount;
                }

                count       = boxControls.Count;
                progressing = 0;
            }
        }
Beispiel #10
0
        public void GenTrack_24Hour_OpenFolder(StartForm startForm)
        {
            memory      = new int[count]; // запоминаем место продолжения генерации
            progressing = 1;
            startForm.Invoke(new MethodInvoker(() => startForm.ProgressBar.Value = 0));

            //очищаем плейлист
            for (int z = 0; z < startForm.TabPlaylist.TabCount; z++)
            {
                startForm.Invoke((MethodInvoker)(() => startForm.TabPlaylist.TabPages[z].Controls.OfType <System.Windows.Forms.TextBox>().First().Clear()));
            }

            List <UIControl> tempBox = new List <UIControl>();               // временный лист

            if (startForm.BlockShuffle)                                      // блоковая генерация
            {
                tempBox.AddRange(boxControls);                               //добавляем контролы во временный лист
                boxControls = boxControls.OrderBy(x => rnd.Next()).ToList(); //перемешать контролы в боксконтролс
            }

            for (int z = 0; z < startForm.TabPlaylist.TabCount; z++)
            {
                for (int i = 0; i < count; i++)
                {
                    if (boxControls[i].NumericHours.Value != 0 || boxControls[i].NumericMinutes.Value != 0)
                    {
                        DirectoryInfo pathInfo = new DirectoryInfo(boxControls[i].TextBoxFolder.Text);


                        //string[] extensions = new[] { ".mp3", ".wav", ".flac" };
                        string[] extensions = Settings.GetAudioFormat();


                        FileInfo[] trackArray = pathInfo.GetFiles("*.*", SearchOption.AllDirectories)
                                                .Where(f => extensions.Contains(f.Extension.ToLower()))
                                                .ToArray();

                        duration = new TimeSpan((int)boxControls[i].NumericHours.Value, (int)boxControls[i].NumericMinutes.Value, 0);
                        hours    = TimeSpan.Zero;

                        if (boxControls[i].TrackMix.Checked)
                        {
                            trackArray = trackArray.OrderBy(x => rnd.Next()).ToArray();
                            Algorithm_Unchecked(trackArray, startForm, z, i);
                        }
                        else
                        {
                            Algorithm_Unchecked(trackArray, startForm, z, i);
                        }
                    }
                }

                if (startForm.AllShuffle)
                {
                    List <string> split = new List <string>(startForm.TabPlaylist.TabPages[z].Controls.OfType <System.Windows.Forms.TextBox>().First().Text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));
                    startForm.Invoke((MethodInvoker)(() => startForm.TabPlaylist.TabPages[z].Controls.OfType <System.Windows.Forms.TextBox>().First().Clear()));
                    int count = split.Count;

                    for (int i = 0; i < count; i++)
                    {
                        int randomNumber = rnd.Next(split.Count);
                        startForm.Invoke((MethodInvoker)(() => startForm.TabPlaylist.TabPages[z].Controls.OfType <System.Windows.Forms.TextBox>().First().Text += split[randomNumber] + "\r\n"));
                        split.RemoveAt(randomNumber);
                    }
                }

                startForm.Invoke(new MethodInvoker(() =>
                {
                    startForm.ProgressBar.Value  = (progressing * 100 / 7);
                    startForm.ProgressLabel.Text = startForm.ProgressBar.Value.ToString() + " %";
                    progressing++;
                }));
            }

            if (startForm.BlockShuffle)
            {
                boxControls = tempBox;
            }
        }