Example #1
0
        /// <summary>
        ///     Moves the passed in item up or down. No effect if upDown is neither 0 nor 1, or item not found.
        /// </summary>
        /// <param name="itemToMoveUp">The item to be moved.</param>
        /// <param name="upDown">0 to move down, 1 to move up.</param>
        /// <returns>The modified list.</returns>
        public List <AudioTaskItem> MoveItem(ListViewItem itemToMoveUp, int upDown)
        {
            if (upDown != 0 && upDown != 1)
            {
                return(null);
            }
            int?          index   = null;
            AudioTaskItem newItem = null;

            foreach (var audioTaskItem in Items)
            {
                if (audioTaskItem.Number.ToString() != itemToMoveUp.Text)
                {
                    continue;
                }
                newItem = audioTaskItem;
                index   = Items.IndexOf(audioTaskItem);
                break;
            }

            if (index == null)
            {
                return(null);
            }

            Items.RemoveAt(Convert.ToInt32(index));
            Items.Insert(upDown == 0
                ? Convert.ToInt32(index) + 1
                : Convert.ToInt32(index) - 1, newItem); // Move up if upDown = 1, otherwise move down.

            IsSaved = false;

            return(Items);
        }
Example #2
0
        /// <summary>
        ///     Append silence audio to the list.
        /// </summary>
        /// <param name="length">Length of the silence audio in milliseconds.</param>
        /// <returns>The modified list.</returns>
        public List <AudioTaskItem> Append(long length)
        {
            var item = new AudioTaskItem(length);

            NumberStack++;

            // Generate silence audio with ffmpeg
            var ffmpeg = new Ffmpeg("./ffmpeg/ffmpeg.exe");
            // var taskBeep = ffmpeg.StartFfmpeg(FFMPEG_ARGS_SILENCE
            //     .Replace("$SECS$", (length * 1000).ToString()
            //         .Replace("$FILE_TEMP$", $"{TempDir}\\{NumberStack}.m4a")), 1000);
            var taskBeep = ffmpeg.StartFfmpeg(string.Format(FFMPEG_ARGS_SILENCE,
                                                            length / 1000,
                                                            $"{TempDir}\\{NumberStack}.mp3"), 1500);

            if (!taskBeep.Result)
            {
                return(null);
            }

            item.AssignNumber(NumberStack, $"{TempDir}/{NumberStack}.mp3");
            Items.Add(item);
            totalDuration += item.Duration;

            IsSaved = false;

            return(Items);
        }
Example #3
0
        /// <summary>
        ///     Append a beep sound to the list.
        /// </summary>
        /// <returns>The modified list.</returns>
        public List <AudioTaskItem> Append()
        {
            var item = new AudioTaskItem();

            NumberStack++;

            File.Copy("./built_in_sound/Beep.mp3",
                      $"{TempDir}/{NumberStack}.mp3");

            item.AssignNumber(NumberStack, $"{TempDir}/{NumberStack}.mp3");
            Items.Add(item);
            totalDuration += item.Duration;

            IsSaved = false;

            return(Items);
        }
Example #4
0
        /// <summary>
        ///     Append Greensleeves audio to the list.
        /// </summary>
        /// <param name="length">Length of the Greensleeves audio in seconds.</param>
        /// <returns>The modified list.</returns>
        public List <AudioTaskItem> Append(int length)
        {
            var item = new AudioTaskItem(length);

            NumberStack++;

            File.Copy($"./built_in_sound/G_{length.ToString()}.mp3",
                      $"{TempDir}/{NumberStack}.mp3");

            item.AssignNumber(NumberStack, $"{TempDir}\\{NumberStack}.mp3");
            Items.Add(item);
            totalDuration += item.Duration;

            IsSaved = false;

            return(Items);
        }
Example #5
0
        // Methods

        #region Methods for modifying List<AudioTaskItem>

        /// <summary>
        ///     Append a general AudioTaskItem to the list.
        /// </summary>
        /// <param name="filepath">Path of file.</param>
        /// <param name="msIn">In location in milliseconds.</param>
        /// <param name="msOut">Out location in milliseconds.</param>
        /// <returns>The modified list.</returns>
        public List <AudioTaskItem> Append(string filepath, long msIn, long msOut)
        {
            var item = new AudioTaskItem(filepath, msIn, msOut);

            NumberStack++;

            File.Copy(filepath,
                      $"{TempDir}/{NumberStack}{Path.GetExtension(filepath)}");

            item.AssignNumber(NumberStack,
                              $"{TempDir}/{NumberStack}{Path.GetExtension(filepath)}");
            Items.Add(item);
            totalDuration += item.Duration;

            IsSaved = false;

            return(Items);
        }
Example #6
0
        /// <summary>
        ///     Load all AudioTaskItems from a file.
        /// </summary>
        /// <param name="filename">Path of the file which will be loaded.</param>
        /// <param name="temp_dir">Path of the temp dir.</param>
        public AudioTaskItemsCollection(string filename, string temp_dir)
        {
            TempDir = temp_dir;
            Items   = new List <AudioTaskItem>();

            // Reads the lmtproj file
            var project_lines = File.ReadAllLines(filename);

            foreach (var line in project_lines)
            {
                var number = int.Parse(line.Split(';')[0]);
                var name   = line.Split(';')[1];
                var secIn  = (long)int.Parse(line.Split(';')[2]);
                var secOut = (long)int.Parse(line.Split(';')[3]);

                AudioTaskItem newItem;
                switch (name)   // Determines beep or silence
                {
                case "$BEEP_SOUND$":
                    // Beep item
                    newItem = new AudioTaskItem();
                    newItem.AssignNumber(number, $"{TempDir}/{number}.mp3");
                    Items.Add(newItem);
                    File.Copy($"./built_in_sound/Beep.mp3",
                              $"{TempDir}/{number}.mp3");
                    return;

                case "$SILENCE_AUDIO$":
                    // Silence audio
                    this.Append(secOut);
                    return;
                }

                // Append Greensleeves music
                if (name.Contains("GREENSLEEVES"))
                {
                    var seconds = "";
                    foreach (var character in name)
                    {
                        if (char.IsDigit(character))
                        {
                            seconds += character;
                        }
                    }
                    newItem = new AudioTaskItem(int.Parse(seconds));
                    newItem.AssignNumber(number, $"{TempDir}/{number}.mp3");
                    Items.Add(newItem);
                    File.Copy($"./built_in_sound/G_{seconds}.mp3",
                              $"{TempDir}/{number}.mp3");
                    return;
                }

                // Append normal audio
                if (!File.Exists(name))
                {
                    continue;                     // Skip file if file is not exist
                }
                newItem = new AudioTaskItem(name, secIn, secOut);
                newItem.AssignNumber(number, $"{TempDir}/{number}{Path.GetExtension(name)}");
                Items.Add(newItem);
                File.Copy(name, $"{TempDir}/{number}{Path.GetExtension(name)}");

                // Add up total time
                totalDuration += secOut - secIn;

                NumberStack = number + 1;
            }
        }