コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: RodelJasper/p4p
        private void ButtonTemplate_Click(object sender, RoutedEventArgs e)
        {
            List <List <string> > listResults = GenerateTempPrompt.Prompt("Enter template name", "Generate template file", inputType: GenerateTempPrompt.InputType.Text);
            string        pathName            = testDBRoot;
            string        ext      = "tpl";
            string        tempName = listResults.First().First() + "." + ext;
            List <string> projN    = new List <string>();

            if (listResults == null)
            {
                return;
            }

            pathName += "\\" + listResults.First().First() + "." + ext;
            try
            {
                // Create a new file
                using (FileStream fs = File.Create(pathName))
                {
                    //Add some text to file
                    Byte[] heading = new UTF8Encoding(true).GetBytes("! this file was generated by Moa \n \n");
                    fs.Write(heading, 0, heading.Length);

                    int count = 0;
                    //The second list must be sfb tracks and sf0 third.
                    foreach (List <string> lStr in listResults)
                    {
                        string trackClassName = "";
                        // skip first result list which contain tpl name and project path
                        if (count == 0)
                        {
                            projN.Add(lStr[1]);
                            count += 1;
                            string pathFiles   = testDBRoot + "\\" + lStr[1] + "\\*";
                            byte[] pathFString = new UTF8Encoding(true).GetBytes("path lab " + pathFiles +
                                                                                 "\n" + "path trg " + pathFiles + "\n" + "path hlb " + pathFiles + "\n" + "path wav " + pathFiles + "\n" + "path sfb " + pathFiles + "\n \n");
                            fs.Write(pathFString, 0, pathFString.Length);

                            byte[] sampleWavString = new UTF8Encoding(true).GetBytes("track samples wav\n");
                            fs.Write(sampleWavString, 0, sampleWavString.Length);
                            continue;
                        }
                        if (lStr.LastOrDefault().Equals("sf0Id"))
                        {
                            trackClassName = "sf0";
                            count         += 1;
                        }
                        else if (lStr.LastOrDefault().Equals("sfbId"))
                        {
                            trackClassName = "sfb";
                            count         += 1;
                        }

                        else
                        {
                            trackClassName = lStr.Last();
                            count         += 1;
                        }
                        foreach (string str in lStr)
                        {
                            if (str.Equals(lStr.Last()))
                            {
                                continue;
                            }
                            // make sure to fix hardcoded sfb
                            byte[] trackString = new UTF8Encoding(true).GetBytes("track " + str + " " + trackClassName + "\n");
                            fs.Write(trackString, 0, trackString.Length);
                        }
                    }

                    byte[] primaryExt = new UTF8Encoding(true).GetBytes("\nset PrimaryExtension wav \n");
                    fs.Write(primaryExt, 0, primaryExt.Length);
                }
                byte[] rawData = File.ReadAllBytes(pathName);
                executeInsert(pathName, ext, null, projN, rawData);
                if (!projectSelectedName.Equals(""))
                {
                    dgl.loadSpeakers(projectSelectedName);
                    rowS = dgl.getCollection("S");

                    buildDatagridGroups(new ListCollectionView(rowS));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
コード例 #2
0
        public static List <List <string> > Prompt(string question, string title, string defaultValue = "", InputType inputType = InputType.Text)
        {
            returnList    = new List <List <string> >();
            nonTrackList  = new List <string>();
            sf0ReturnList = new List <string>();
            sfbReturnList = new List <string>();

            pitchOptions = new List <String>();
            formOptions  = new List <String>();
            pitchCB      = new List <ComboBox>();
            formCB       = new List <ComboBox>();
            GenerateTempPrompt inst = new GenerateTempPrompt(question, title, defaultValue, inputType);

            inst.ShowDialog();
            string [] templateNames = new string[2];

            if (inst.DialogResult == true)
            {
                // user must enter a template name
                if (inst.txtFolderName.Text != defaultValue)
                {
                    // user must choose an existing project
                    nonTrackList.Add(inst.txtFolderName.Text);

                    if (inst.cbChooseFolder.SelectedValue != null)
                    {
                        // non track list gathers all the user input not associated to the track level, this statement gets existing project
                        nonTrackList.Add((string)inst.cbChooseFolder.SelectedValue);
                        returnList.Add(nonTrackList);

                        // if the user selected a formant track value to add to the template file
                        if (inst.formTrack1.SelectedValue != null)
                        {
                            sfbReturnList.Add((string)inst.formTrack1.SelectedValue);
                        }
                        else if (!inst.formTrack1.Text.Equals(defaultValue))
                        {
                            sfbReturnList.Add(inst.formTrack1.Text);
                        }

                        // when the user has added more comboboxes for sfb, check to see if more track values were selected
                        if (formCB.Count >= 1)
                        {
                            // Future works. Need to get only distinct.
                            foreach (ComboBox cb in formCB)
                            {
                                if (cb.SelectedValue != null && !sfbReturnList.Contains(cb.SelectedValue))
                                {
                                    sfbReturnList.Add((string)cb.SelectedValue);
                                }
                                else if (!cb.Text.Equals(defaultValue) && !sfbReturnList.Contains(cb.Text))
                                {
                                    sfbReturnList.Add(cb.Text);
                                }
                            }
                        }

                        if (sfbReturnList.Count > 0)
                        {
                            inst.insertToTable(formIdentifier);
                            sfbReturnList.Add("sfbId");
                            returnList.Add(sfbReturnList);
                        }

                        // For the Pitch track class. if the user selected a pitch track value to add to the template file
                        if (inst.pitchTrack1.SelectedValue != null)
                        {
                            sf0ReturnList.Add((string)inst.pitchTrack1.SelectedValue);
                        }

                        else if (!inst.pitchTrack1.Text.Equals(defaultValue))
                        {
                            sf0ReturnList.Add(inst.pitchTrack1.Text);
                        }
                        // when the user has added more comboboxes for sf0, check to see if more track values were selected
                        if (pitchCB.Count >= 1)
                        {
                            foreach (ComboBox cb in pitchCB)
                            {
                                if (cb.SelectedValue != null && !sf0ReturnList.Contains(cb.SelectedValue))
                                {
                                    sf0ReturnList.Add((string)cb.SelectedValue);
                                }
                                else if (!cb.Text.Equals(defaultValue) && !sf0ReturnList.Contains(cb.Text))
                                {
                                    sf0ReturnList.Add(cb.Text);
                                }
                            }
                        }
                        if (sf0ReturnList.Count > 0)
                        {
                            inst.insertToTable(pitchIdentifier);
                            sf0ReturnList.Add("sf0Id");
                            returnList.Add(sf0ReturnList);
                        }

                        // For other type of extension. add to the template file
                        if (!inst.otherTrack1.Text.Equals(defaultValue))
                        {
                            otherTrackList.Add(inst.otherTrack1.Text);
                        }
                        // when the user has added more comboboxes for sf0, check to see if more track values were selected
                        if (otherTB.Count >= 1)
                        {
                            foreach (TextBox tb in otherTB)
                            {
                                if (!tb.Text.Equals(defaultValue) && !otherTrackList.Contains(tb.Text))
                                {
                                    otherTrackList.Add(tb.Text);
                                }
                            }
                        }
                        if (otherTrackList.Count > 0)
                        {
                            otherTrackList.Add(inst.txtTrackOther.Text);
                            returnList.Add(otherTrackList);
                        }
                        return(returnList);
                    }
                    else
                    {
                        MessageBox.Show("Please choose a project folder for the template file.");
                        Prompt(question, title, defaultValue, inputType);
                    }
                }

                // if the user didn't choose any, should throw exception
                else
                {
                    MessageBox.Show("Please enter a name for the template file.");
                    Prompt(question, title, defaultValue, inputType);
                }
            }
            //System.Console.WriteLine();
            return(null);
        }
コード例 #3
0
        public static List<List<string>> Prompt(string question, string title, string defaultValue = "", InputType inputType = InputType.Text)
        {
            returnList = new List<List<string>>();
            nonTrackList = new List<string>();
            sf0ReturnList = new List<string>();
            sfbReturnList = new List<string>();

            pitchOptions = new List<String>();
            formOptions = new List<String>();
            pitchCB = new List<ComboBox>();
            formCB = new List<ComboBox>();
            GenerateTempPrompt inst = new GenerateTempPrompt(question, title, defaultValue, inputType);

            inst.ShowDialog();
            string [] templateNames = new string[2];

            if (inst.DialogResult == true)
            {
                // user must enter a template name
                if (inst.txtFolderName.Text != defaultValue)
                {
                    // user must choose an existing project
                    nonTrackList.Add(inst.txtFolderName.Text);

                    if (inst.cbChooseFolder.SelectedValue != null)
                    {
                        // non track list gathers all the user input not associated to the track level, this statement gets existing project
                        nonTrackList.Add((string)inst.cbChooseFolder.SelectedValue);
                        returnList.Add(nonTrackList);

                        // if the user selected a formant track value to add to the template file
                        if (inst.formTrack1.SelectedValue != null)
                        {
                            sfbReturnList.Add((string)inst.formTrack1.SelectedValue);
                        }
                        else if (!inst.formTrack1.Text.Equals(defaultValue))
                        {
                            sfbReturnList.Add(inst.formTrack1.Text);

                        }

                        // when the user has added more comboboxes for sfb, check to see if more track values were selected
                        if (formCB.Count >= 1)
                        {
                            // Future works. Need to get only distinct.
                            foreach (ComboBox cb in formCB)
                            {
                                if (cb.SelectedValue != null && !sfbReturnList.Contains(cb.SelectedValue))
                                {
                                    sfbReturnList.Add((string)cb.SelectedValue);
                                }
                                else if (!cb.Text.Equals(defaultValue) && !sfbReturnList.Contains(cb.Text))
                                {
                                    sfbReturnList.Add(cb.Text);
                                }
                            }
                        }

                        if (sfbReturnList.Count > 0)
                        {
                            inst.insertToTable(formIdentifier);
                            sfbReturnList.Add("sfbId");
                            returnList.Add(sfbReturnList);
                        }

                        // For the Pitch track class. if the user selected a pitch track value to add to the template file
                        if (inst.pitchTrack1.SelectedValue != null)
                        {
                            sf0ReturnList.Add((string)inst.pitchTrack1.SelectedValue);
                        }

                        else if (!inst.pitchTrack1.Text.Equals(defaultValue))
                        {
                            sf0ReturnList.Add(inst.pitchTrack1.Text);

                        }
                        // when the user has added more comboboxes for sf0, check to see if more track values were selected
                        if (pitchCB.Count >= 1)
                        {
                            foreach (ComboBox cb in pitchCB)
                            {
                                if (cb.SelectedValue != null && !sf0ReturnList.Contains(cb.SelectedValue))
                                    sf0ReturnList.Add((string)cb.SelectedValue);
                                else if (!cb.Text.Equals(defaultValue) && !sf0ReturnList.Contains(cb.Text))
                                    sf0ReturnList.Add(cb.Text);
                            }
                        }
                        if (sf0ReturnList.Count > 0)
                        {
                            inst.insertToTable(pitchIdentifier);
                            sf0ReturnList.Add("sf0Id");
                            returnList.Add(sf0ReturnList);
                        }

                        // For other type of extension. add to the template file
                        if (!inst.otherTrack1.Text.Equals(defaultValue))
                        {
                            otherTrackList.Add(inst.otherTrack1.Text);

                        }
                        // when the user has added more comboboxes for sf0, check to see if more track values were selected
                        if (otherTB.Count >= 1)
                        {
                            foreach (TextBox tb in otherTB)
                            {
                                if (!tb.Text.Equals(defaultValue) && !otherTrackList.Contains(tb.Text))
                                    otherTrackList.Add(tb.Text);
                            }
                        }
                        if (otherTrackList.Count > 0)
                        {
                            otherTrackList.Add(inst.txtTrackOther.Text);
                            returnList.Add(otherTrackList);
                        }
                        return returnList;
                    }
                    else {
                        MessageBox.Show("Please choose a project folder for the template file.");
                        Prompt(question, title, defaultValue, inputType);
                    }

                }

                // if the user didn't choose any, should throw exception
                else
                {
                    MessageBox.Show("Please enter a name for the template file.");
                    Prompt(question, title, defaultValue, inputType);
                }
            }
            //System.Console.WriteLine();
            return null;
        }