Exemplo n.º 1
0
        private int[] getTime(string timeString)
        {
            //take a string input and output 4 time ints (hour,min,sec,millisec
            int timeHour = 0;
            int timeMin = 0;
            int timeSec = 0;
            int timeMSec = 0;
            string timeHourS = "00";
            string TimeMinS = "00";
            string timeSecS = "00";
            string timeMSecS = "00";
            int timeType = 0;
            int location = timeString.Length;
            try
            {
                for (int i = timeString.Length; i > 0; i--)
                {
                    if (timeType == 0)//if currently finding seconds
                    {
                        if (timeString[i - 1] == '.')//if it includes milliseconds
                        {
                            timeMSecS = timeString.Substring(i, timeString.Length - i);
                            timeMSec = Convert.ToInt32(timeMSecS);
                            location = i - 1;
                        }
                        if (timeString[i - 1] == ':')
                        {

                            timeSecS = timeString.Substring(i, location - i);
                            timeSec = Convert.ToInt32(timeSecS);
                            timeType++;
                            location = i;
                        }
                    }
                    else if (timeType == 1)//if currently finding minutes
                    {
                        if (timeString[i - 1] == ':')
                        {
                            TimeMinS = timeString.Substring(i, location - i - 1);
                            timeMin = Convert.ToInt32(TimeMinS);
                            timeType++;
                            location = i;
                        }
                    }
                }
                if (timeType == 1)//if there was one : the remaining numbers are minutes
                {
                    TimeMinS = timeString.Substring(0, location - 1);
                    timeMin = Convert.ToInt32(TimeMinS);
                }
                else if (timeType == 2)//if there were two : the remaining numbers are hours
                {
                    timeHourS = timeString.Substring(0, location - 1);
                    timeHour = Convert.ToInt32(timeHourS);
                }
            }
            catch (Exception e)//exception to catch any errors
            {
                Console.WriteLine("Invalid Time Code");
                InvalidTime prompt = new InvalidTime();
                prompt.ShowDialog();
                Console.WriteLine(e.Message);
                int[] returnValue0 = { 0, 0, 0, 0 };
                return returnValue0;
            }
            if (timeMin > 60 || timeSec > 60 || timeMSec > 1000)//catch if the times are too large
            {
                Console.WriteLine("Invalid Time Code");
                InvalidTime prompt = new InvalidTime();
                prompt.ShowDialog();
                int[] returnValue0 = { 0, 0, 0, 0 };
                return returnValue0;
            }
            int[] returnValue = { timeHour, timeMin, timeSec, timeMSec };
            return returnValue;
        }
Exemplo n.º 2
0
        private void adjustEnd(string filePath, StringBuilder sb)
        {
            //takes the time from the textbox and the direction from the button then adjust the ending time of every segment
            string[] origFile = getText(filePath);
            if (origFile == null)
            {
                return;
            }
            string changeTime = adjustendText.Text;//get the change time
            Boolean adjustLater = false;//get the direction of the change
            if (adjustendBox.Text == "+")
            {
                adjustLater = true;
            }
            int changeMS = 0;
            try
            {
                changeMS = Int32.Parse(changeTime);
            }
            catch (Exception e)
            {
                Console.WriteLine("Invalid Time Code");
                InvalidTime errormessage = new InvalidTime();
                errormessage.ShowDialog();
                Console.WriteLine(e.Message);
                return;
            }

            //get the clip name
            string clipBaseName = origFile[2].Substring(2, origFile[2].Length - 3);

            //start outputting to a new file while modifying it
            // Set a variable to the My Documents path.
            string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            //StringBuilder sb = new StringBuilder();

            //Start building the file
            int clipCount = 1;
            int segStart = 4;
            int segEnd = origFile.Length - 1;
            sb.AppendLine(origFile[0]);//write in the transcript name through the first segment
            sb.AppendLine();
            sb.AppendLine("C(" + clipBaseName + "-" + clipCount + ")");
            clipCount++;

            for (int i = segStart; i < segEnd; i++)
            {
                //get the start time, adjut it, rewrite that section of the line, and then append the line
                string segEndTime = origFile[i].Substring(37, 12);
                string output = origFile[i];
                string newSegEndTime = segEndTime;
                int[] checkSegEndTime = getTime(segEndTime);
                int currentMS = toMilSec(checkSegEndTime);//get the current time in milliseconds
                int newMS = currentMS;
                if (adjustLater)
                {
                    newMS = currentMS + changeMS;
                    newSegEndTime = milSecToString(newMS);
                    output = origFile[i].Substring(0, 37) + newSegEndTime + origFile[i].Substring(49, 1);
                }
                else
                {
                    newMS = currentMS - changeMS;
                    newSegEndTime = milSecToString(newMS);
                    output = origFile[i].Substring(0, 37) + newSegEndTime + origFile[i].Substring(49, 1);
                }
                sb.AppendLine(output);

            }

            // Write the stream contents to a new file with the file name + "EDIT".
            string fullPath = textBox1.Text;
            string fileName = fullPath.Substring(mydocpath.Length + 1, fullPath.Length - mydocpath.Length - 5);
            using (StreamWriter outfile = new StreamWriter(mydocpath + @"\" + fileName + "EDIT.ccs"))
            {
                outfile.Write(sb.ToString());
            }

            Completed prompt = new Completed();
            prompt.ShowDialog();
        }