public void Convert(string zigSrcPath, string destPath)
        {
            var     deser = new XmlSerializer(typeof(ZpeSong));
            ZpeSong zigSong;

            using (FileStream stream = new FileStream(zigSrcPath, FileMode.Open))
            {
                zigSong = (ZpeSong)deser.Deserialize(stream);
            }

            if (zigSong.PueVersion != 46)
            {
                throw new Exception("Incompatable version of Ziggy Pro Editor XML file");
            }

            bool          foundTrack = false;
            StringBuilder sb         = new StringBuilder();

            // cross matching arrangment arrays
            string[] rsArray  = new string[] { "Lead", "Rhythm", "Bass" };
            string[] zigArray = new string[] { "PART REAL_GUITAR_22", "PART REAL_GUITAR", "PART REAL_BASS_22" };
            int      arrIndex = -1;

            foreach (var arrangement in zigArray)
            {
                arrIndex++;
                var guitarTrack = zigSong.Tracks.SingleOrDefault(tr => arrangement.Equals(tr.Name));

                if (guitarTrack == null)
                {
                    continue;
                    //throw new Exception("Couldn't find a guitar track");
                }

                foundTrack = true;
                var rsSong = new Song2014();
                AddSongMetadata(rsSong, zigSong, rsArray[arrIndex]);
                AddEbeats(rsSong, zigSong, arrangement);
                AddNotes(rsSong, zigSong, arrangement);
                AddToneProps(rsSong, rsArray[arrIndex]);

                var destDir     = Path.GetDirectoryName(destPath);
                var destName    = Path.GetFileNameWithoutExtension(destPath);
                var xmlDestPath = String.Format("{0}_{1}.xml", Path.Combine(destDir, destName), rsArray[arrIndex]);

                using (FileStream stream = new FileStream(xmlDestPath, FileMode.Create))
                {
                    rsSong.Serialize(stream, true);
                }
            }

            if (!foundTrack)
            {
                throw new NullReferenceException("Did not find any Rocksmith 2014 compatible Ziggy Pro tracks in " + Path.GetFileName(zigSrcPath) + Environment.NewLine);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Convert RS2014 (Song2014) to XML file
        /// </summary>
        /// <param name="rs2014Song"></param>
        /// <param name="outputDir"></param>
        /// <returns>RS2014 XML file path</returns>
        public string Song2014ToXml(Song2014 rs2014Song, string outputDir)
        {
            var outputFile = String.Format("{0}_{1}", rs2014Song.Title, rs2014Song.Arrangement);

            outputFile = String.Format("{0}{1}", outputFile.GetValidName(false, true).ToLower(), "_rs2014.xml");
            var outputPath = Path.Combine(outputDir, outputFile);

            if (File.Exists(outputPath))
            {
                File.Delete(outputPath);
            }

            using (var stream = File.OpenWrite(outputPath))
            {
                rs2014Song.Serialize(stream, false);
            }

            return(outputPath);
        }
Beispiel #3
0
        /// <summary>
        /// Convert RS2014 (Song2014) to XML file
        /// </summary>
        /// <param name="rs2014Song"></param>
        /// <param name="outputPath"></param>
        /// <param name="overWrite"></param>
        /// <returns>RS2014 XML file path</returns>
        public string Song2014ToXml(Song2014 rs2014Song, string outputPath, bool overWrite)
        {
            if (File.Exists(outputPath) && overWrite)
            {
                File.Delete(outputPath);
            }
            else
            {
                var outputDir  = Path.GetDirectoryName(outputPath);
                var outputFile = String.Format("{0}_{1}", rs2014Song.Title, rs2014Song.Arrangement);
                outputFile = String.Format("{0}{1}", outputFile.ToLower().GetValidFileName(), "_rs2014.xml");
                outputPath = Path.Combine(outputDir, outputFile);
            }

            using (var stream = File.OpenWrite(outputPath))
            {
                rs2014Song.Serialize(stream, false);
            }

            return(outputPath);
        }
Beispiel #4
0
        // TODO: apply before generate, like metronome arrangements does
        // only for RS2014
        public static bool ApplyBassFix(Arrangement arr)
        {
            if (arr.TuningPitch.Equals(220.0))
            {
                // MessageBox.Show("This song is already at 220Hz pitch (bass fixed applied already?)", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            var      songFile = arr.SongXml.File;
            var      comments = Song2014.ReadXmlComments(songFile);
            Song2014 songXml  = Song2014.LoadFromFile(songFile);

            // Force 220Hz
            arr.TuningPitch    = 220.0;
            songXml.CentOffset = "-1200.0";
            // Octave up for each string
            Int16[] strings = arr.TuningStrings.ToArray();
            for (int s = 0; s < strings.Length; s++)
            {
                if (strings[s] < 0)
                {
                    strings[s] += 12;
                }
            }

            //Detect tuning
            var tuning = TuningDefinitionRepository.Instance.Detect(new TuningStrings(strings), GameVersion.RS2014, true);

            arr.Tuning        = tuning.UIName = tuning.Name = String.Format("{0} Fixed", tuning.Name);// bastartd bass hack, huh?
            arr.TuningStrings = songXml.Tuning = tuning.Tuning;
            TuningDefinitionRepository.Instance.Save(true);

            File.Delete(songFile);
            using (var stream = File.OpenWrite(songFile))
            {
                songXml.Serialize(stream, true);
            }
            Song2014.WriteXmlComments(songFile, comments, false);

            return(true);
        }
Beispiel #5
0
        public bool LoadXmlArrangement(string xmlFilePath)
        {
            if (isAlreadyAdded(xmlFilePath))
            {
                MessageBox.Show(@"XML Arrangement: " + Path.GetFileName(xmlFilePath) + "   " + Environment.NewLine +
                                @"has already been added.  Please choose a new file. ",
                                DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            try
            {
                bool isVocal     = false;
                bool isShowlight = false;
                try
                {
                    xmlSong = Song2014.LoadFromFile(xmlFilePath);
                    Arrangement.XmlComments = Song2014.ReadXmlComments(xmlFilePath);
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.Message.ToLower().Contains("<vocals"))
                    {
                        isVocal = true;
                    }
                    else if (ex.InnerException.Message.ToLower().Contains("<showlights"))
                    {
                        isShowlight = true;
                    }
                    else
                    {
                        MessageBox.Show(@"Unable to get information from XML arrangement:  " + Environment.NewLine +
                                        Path.GetFileName(xmlFilePath) + Environment.NewLine +
                                        @"It may not be a valid arrangment or " + Environment.NewLine +
                                        @"your version of the EOF may be out of date." + Environment.NewLine +
                                        ex.Message, DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return(false);
                    }
                }

                // SETUP FIELDS
                if (isVocal)
                {
                    arrangementTypeCombo.SelectedItem = ArrangementType.Vocal;
                    _arrangement.ArrangementType      = ArrangementType.Vocal;
                }
                else if (isShowlight)
                {
                    arrangementTypeCombo.SelectedItem = ArrangementType.ShowLight;
                    _arrangement.ArrangementType      = ArrangementType.ShowLight;
                }
                else
                {
                    var version = GameVersion.None;
                    //Detect arrangement GameVersion
                    if (xmlSong != null && xmlSong.Version != null)
                    {
                        var verAttrib = Convert.ToInt32(xmlSong.Version);
                        if (verAttrib <= 6)
                        {
                            version = GameVersion.RS2012;
                        }
                        else if (verAttrib >= 7)
                        {
                            version = GameVersion.RS2014;
                        }
                    }
                    else if (currentGameVersion == GameVersion.RS2012)
                    {
                        // add missing XML elements
                        xmlSong.Version = "4";
                        xmlSong.Tuning  = new TuningStrings {
                            String0 = 0, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0
                        };
                        xmlSong.ArrangementProperties = new SongArrangementProperties2014 {
                            StandardTuning = 1
                        };
                        version = GameVersion.RS2012;
                    }
                    else if (currentGameVersion == GameVersion.None)
                    {
                        using (var obj = new Rs1Converter())
                        {
                            xmlSong = null;
                            xmlSong = obj.SongToSong2014(Song.LoadFromFile(XmlFilePath.Text));
                        }
                        currentGameVersion = GameVersion.RS2014;
                    }
                    else
                    {
                        MessageBox.Show("Your version of EOF may be out of date, please update.", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    // TODO: fix error checking logic for new types of conversion
                    if (currentGameVersion != version && version != GameVersion.None)
                    {
                        Debug.WriteLine(String.Format("Please choose valid Rocksmith {0} arrangement file!", currentGameVersion));
                        //XmlFilePath.Text = "";
                        //return;
                    }

                    // SONG AND ARRANGEMENT INFO / ROUTE MASK
                    BonusCheckBox.Checked = Equals(xmlSong.ArrangementProperties.BonusArr, 1);
                    MetronomeCb.Checked   = Equals(xmlSong.ArrangementProperties.Metronome, 2);
                    if (!EditMode)
                    {
                        string arr = xmlSong.Arrangement.ToLowerInvariant();
                        if (arr.Contains("guitar") || arr.Contains("lead") || arr.Contains("rhythm") || arr.Contains("combo"))
                        {
                            arrangementTypeCombo.SelectedItem = ArrangementType.Guitar;

                            if (arr.Contains("combo"))
                            {
                                arrangementNameCombo.SelectedItem = ArrangementName.Combo;
                                if (currentGameVersion != GameVersion.RS2012)
                                {
                                    RouteMask = RouteMask.Lead;
                                }
                            }
                            else if (arr.Contains("guitar_22") || arr.Contains("lead") || Equals(xmlSong.ArrangementProperties.PathLead, 1))
                            {
                                arrangementNameCombo.SelectedItem = ArrangementName.Lead;
                                if (currentGameVersion != GameVersion.RS2012)
                                {
                                    RouteMask = RouteMask.Lead;
                                }
                            }
                            else if (arr.Contains("guitar") || arr.Contains("rhythm") || Equals(xmlSong.ArrangementProperties.PathRhythm, 1))
                            {
                                arrangementNameCombo.SelectedItem = ArrangementName.Rhythm;
                                if (currentGameVersion != GameVersion.RS2012)
                                {
                                    RouteMask = RouteMask.Rhythm;
                                }
                            }
                        }
                        else if (arr.Contains("bass"))
                        {
                            arrangementTypeCombo.SelectedItem = ArrangementType.Bass;

                            //SetTuningCombo(xmlSong.Tuning, true);
                            Picked.Checked = Equals(xmlSong.ArrangementProperties.BassPick, 1);
                            if (currentGameVersion != GameVersion.RS2012)
                            {
                                RouteMask = RouteMask.Bass;
                                //Low tuning fix for bass, If lowstring is B and bass fix not applied
                                if (xmlSong.Tuning.String0 < -4 && this.frequencyTB.Text == "440")
                                {
                                    bassFix |= MessageBox.Show("Your tuning is too low, would you like to apply \"Low Tuning Fix?\"\n" + "Note, that this won't work if you re-save arangement in EOF.\n", "Low Tuning Fix Required!", MessageBoxButtons.YesNo) == DialogResult.Yes;
                                }
                            }
                        }
                    }

                    if (currentGameVersion != GameVersion.RS2012)
                    {
                        //Tones setup
                        Arrangement.ToneBase        = xmlSong.ToneBase;
                        Arrangement.ToneA           = xmlSong.ToneA;
                        Arrangement.ToneB           = xmlSong.ToneB;
                        Arrangement.ToneC           = xmlSong.ToneC;
                        Arrangement.ToneD           = xmlSong.ToneD;
                        Arrangement.ToneMultiplayer = null;

                        SetupTones(Arrangement);

                        //Apply bass Fix, refactor me.
                        if (bassFix)
                        {
                            bassFix = false;
                            Arrangement.SongXml.File = XmlFilePath.Text;
                            parentControl.ApplyBassFix(Arrangement);
                        }
                    }

                    // Setup tuning
                    var selectedType = new ArrangementType();
                    if (xmlSong.Arrangement.ToLower() == "bass")
                    {
                        selectedType = ArrangementType.Bass;
                    }
                    else
                    {
                        selectedType = ArrangementType.Guitar;
                    }

                    FillTuningCombo(selectedType, currentGameVersion);

                    // find tuning in tuningComboBox list and make selection
                    int foundTuning = -1;
                    for (int tcbIndex = 0; tcbIndex < tuningComboBox.Items.Count; tcbIndex++)
                    {
                        tuningComboBox.SelectedIndex = tcbIndex;
                        TuningDefinition tuning = (TuningDefinition)tuningComboBox.Items[tcbIndex];
                        if (tuning.Tuning == xmlSong.Tuning)
                        {
                            foundTuning = tcbIndex;
                            break;
                        }
                    }

                    if (foundTuning == -1 && selectedType != ArrangementType.Bass)
                    {
                        tuningComboBox.SelectedIndex = 0;
                        ShowTuningForm(selectedType, new TuningDefinition {
                            Tuning = xmlSong.Tuning, Custom = true, GameVersion = currentGameVersion
                        });
                    }
                    else
                    {
                        // E Standard, Drop D, and Open E tuning are same for both guitar and bass
                        if (selectedType == ArrangementType.Bass)
                        {
                            if (xmlSong.Tuning.String4 == 0 && xmlSong.Tuning.String5 == 0)
                            {
                                Debug.WriteLine("Bass Tuning is the same as Guitar Tuning");
                            }
                            else
                            {
                                tuningComboBox.SelectedIndex = 0;
                                MessageBox.Show("Toolkit was not able to automatically set tuning for  " + Environment.NewLine +
                                                "Bass Arrangement: " + Path.GetFileName(xmlFilePath) + Environment.NewLine +
                                                "Use the tuning selector dropdown or Tunining Editor  " + Environment.NewLine +
                                                "to manually set the correct bass tuning.", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                    }

                    tuningComboBox.Refresh();

                    Arrangement.Tuning        = tuningComboBox.SelectedItem.ToString();
                    Arrangement.TuningStrings = xmlSong.Tuning;
                    Arrangement.CapoFret      = xmlSong.Capo;
                    frequencyTB.Text          = Arrangement.TuningPitch.ToString();
                    UpdateCentOffset();

                    // save converted RS1 to RS2014 Song2014 XML
                    if (version == GameVersion.None)
                    {
                        var srcDir        = Path.GetDirectoryName(XmlFilePath.Text);
                        var srcName       = Path.GetFileNameWithoutExtension(XmlFilePath.Text);
                        var backupSrcPath = String.Format("{0}_{1}.xml", Path.Combine(srcDir, srcName), "RS1");

                        // backup original RS1 file
                        File.Copy(XmlFilePath.Text, backupSrcPath);

                        // write converted RS1 file
                        using (FileStream stream = new FileStream(XmlFilePath.Text, FileMode.Create))
                            xmlSong.Serialize(stream, true);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(@"Unable to get information from XML arrangement:  " + Environment.NewLine +
                                Path.GetFileName(xmlFilePath) + Environment.NewLine +
                                @"It may not be a valide arrangment or " + Environment.NewLine +
                                @"your version of the EOF may be out of date." + Environment.NewLine +
                                ex.Message, DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            return(true);
        }
Beispiel #6
0
        public bool LoadXmlArrangement(string xmlFilePath)
        {
            // only use this method when adding arrangements
            if (EditMode)
                return false;

            Arrangement = new Arrangement
            {
                SongFile = new SongFile { File = "" },
                SongXml = new SongXML { File = xmlFilePath }
            };

            try
            {
                // SETUP FIELDS
                if (xmlFilePath.ToLower().EndsWith("vocals.xml") || xmlFilePath.ToLower().EndsWith("vocals_rs2.xml"))
                {
                    cmbArrangementType.SelectedItem = ArrangementType.Vocal;
                    Arrangement.ArrangementType = ArrangementType.Vocal;

                    if (xmlFilePath.ToLower().EndsWith("_jvocals.xml") || xmlFilePath.ToLower().EndsWith("jvocals_rs2.xml"))
                        cmbArrangementName.SelectedItem = ArrangementName.JVocals;
                    else
                        cmbArrangementName.SelectedItem = ArrangementName.Vocals;
                }
                else if (xmlFilePath.ToLower().EndsWith("_showlights.xml"))
                {
                    cmbArrangementType.SelectedItem = ArrangementType.ShowLight;
                    Arrangement.ArrangementType = ArrangementType.ShowLight;
                }
                else
                {
                    _xmlSong = Song2014.LoadFromFile(xmlFilePath);
                    var version = GameVersion.None;
                    // Detect Arrangement GameVersion
                    if (_xmlSong != null && _xmlSong.Version != null)
                    {
                        var verAttrib = Convert.ToInt32(_xmlSong.Version);
                        if (verAttrib <= 6) version = GameVersion.RS2012;
                        else if (verAttrib >= 7) version = GameVersion.RS2014;
                    }
                    else
                        switch (_gameVersion)
                        {
                            case GameVersion.RS2012:
                                // add missing XML elements
                                _xmlSong.Version = "4";
                                _xmlSong.Tuning = new TuningStrings { String0 = 0, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0 };
                                _xmlSong.ArrangementProperties = new SongArrangementProperties2014 { StandardTuning = 1 };
                                version = GameVersion.RS2012;
                                break;
                            case GameVersion.None:
                                using (var obj = new Rs1Converter())
                                {
                                    _xmlSong = null;
                                    _xmlSong = obj.SongToSong2014(Song.LoadFromFile(xmlFilePath));
                                }
                                _gameVersion = GameVersion.RS2014;
                                break;
                            default:
                                MessageBox.Show("Your version of EOF may be out of date, please update.", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                break;
                        }

                    // TODO: fix error checking logic for new types of conversion
                    if (_gameVersion != version && version != GameVersion.None)
                    {
                        Debug.WriteLine("Please choose valid Rocksmith {0} Arrangement file!", _gameVersion);
                        //XmlFilePath.Text = "";
                        //return;
                    }

                    // SONG AND ARRANGEMENT INFO / ROUTE MASK
                    chkBonusArrangement.Checked = Equals(_xmlSong.ArrangementProperties.BonusArr, 1);
                    chkMetronome.Checked = Equals(_xmlSong.ArrangementProperties.Metronome, 2);
                    Arrangement.ArrangementPropeties = _xmlSong.ArrangementProperties;
                    Arrangement.CapoFret = _xmlSong.Capo;
                    Arrangement.TuningStrings = _xmlSong.Tuning;

                    if (!String.IsNullOrEmpty(_xmlSong.CentOffset))
                        Arrangement.TuningPitch = Convert.ToDouble(_xmlSong.CentOffset).Cents2Frequency();

                    txtFrequency.Text = (Arrangement.TuningPitch > 0) ? Arrangement.TuningPitch.ToString() : "440.00";

                    var arr = _xmlSong.Arrangement.ToLowerInvariant();

                    if (arr.Contains("guitar") || arr.Contains("lead") || arr.Contains("rhythm") || arr.Contains("combo"))
                    {
                        cmbArrangementType.SelectedItem = ArrangementType.Guitar;
                        Arrangement.ArrangementType = ArrangementType.Guitar;

                        if (arr.Contains("combo"))
                        {
                            cmbArrangementName.SelectedItem = ArrangementName.Combo;
                            if (_gameVersion != GameVersion.RS2012) RouteMask = RouteMask.Lead;
                        }
                        else if (arr.Contains("guitar_22") || arr.Contains("lead") || Equals(_xmlSong.ArrangementProperties.PathLead, 1))
                        {
                            cmbArrangementName.SelectedItem = ArrangementName.Lead;
                            if (_gameVersion != GameVersion.RS2012) RouteMask = RouteMask.Lead;
                        }
                        else if (arr.Contains("guitar") || arr.Contains("rhythm") || Equals(_xmlSong.ArrangementProperties.PathRhythm, 1))
                        {
                            cmbArrangementName.SelectedItem = ArrangementName.Rhythm;
                            if (_gameVersion != GameVersion.RS2012) RouteMask = RouteMask.Rhythm;
                        }
                    }
                    else if (arr.Contains("bass"))
                    {
                        cmbArrangementType.SelectedItem = ArrangementType.Bass;
                        Arrangement.ArrangementType = ArrangementType.Bass;
                        chkBassPicked.Checked = Equals(_xmlSong.ArrangementProperties.BassPick, 1);
                        if (_gameVersion != GameVersion.RS2012) RouteMask = RouteMask.Bass;
                    }

                    if (_gameVersion != GameVersion.RS2012)
                    {
                        //Tones setup //TODO: add parsing tones events
                        Arrangement.ToneBase = _xmlSong.ToneBase;
                        Arrangement.ToneA = _xmlSong.ToneA;
                        Arrangement.ToneB = _xmlSong.ToneB;
                        Arrangement.ToneC = _xmlSong.ToneC;
                        Arrangement.ToneD = _xmlSong.ToneD;
                        Arrangement.ToneMultiplayer = null;
                        SetupTones(Arrangement);
                    }

                    if (Arrangement.ArrangementType == ArrangementType.Bass)
                        FixBassTuning();

                    SelectTuningName();
                    CheckTuning();

                    // save converted RS1 to RS2014 Song2014 XML
                    if (version == GameVersion.None)
                    {
                        var srcDir = Path.GetDirectoryName(xmlFilePath);
                        var srcName = Path.GetFileNameWithoutExtension(xmlFilePath);
                        var backupSrcPath = String.Format("{0}_{1}.xml", Path.Combine(srcDir, srcName), "RS1");

                        // backup original RS1 file
                        File.Copy(xmlFilePath, backupSrcPath);

                        // write converted RS1 file
                        using (var stream = new FileStream(xmlFilePath, FileMode.Create))
                            _xmlSong.Serialize(stream, true);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(@"Unable to get information from XML Arrangement:  " + Environment.NewLine +
                                Path.GetFileName(xmlFilePath) + Environment.NewLine +
                                @"It may not be a valid Arrangement or " + Environment.NewLine +
                                @"your version of the EOF may be out of date." + Environment.NewLine +
                                ex.Message, DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }

            return true;
        }
Beispiel #7
0
        public bool LoadXmlArrangement(string xmlFilePath)
        {
            if (IsAlreadyAdded(xmlFilePath))
            {
                MessageBox.Show(@"XML Arrangement: " + Path.GetFileName(xmlFilePath) + @"   " + Environment.NewLine +
                                @"has already been added.  Please choose a new file. ",
                                DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            try
            {
                bool isVocal     = false;
                bool isShowlight = false;
                try
                {
                    xmlSong = Song2014.LoadFromFile(xmlFilePath);
                    Arrangement.XmlComments = Song2014.ReadXmlComments(xmlFilePath);
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.Message.ToLower().Contains("<vocals"))
                    {
                        isVocal = true;
                    }
                    else if (ex.InnerException.Message.ToLower().Contains("<showlights"))
                    {
                        isShowlight = true;
                    }
                    else
                    {
                        MessageBox.Show(@"Unable to get information from XML arrangement:  " + Environment.NewLine +
                                        Path.GetFileName(xmlFilePath) + Environment.NewLine +
                                        @"It may not be a valid arrangement or " + Environment.NewLine +
                                        @"your version of the EOF may be out of date." + Environment.NewLine +
                                        ex.Message, DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return(false);
                    }
                }

                // SETUP FIELDS
                if (isVocal)
                {
                    arrangementTypeCombo.SelectedItem = ArrangementType.Vocal;
                    _arrangement.ArrangementType      = ArrangementType.Vocal;
                }
                else if (isShowlight)
                {
                    arrangementTypeCombo.SelectedItem = ArrangementType.ShowLight;
                    _arrangement.ArrangementType      = ArrangementType.ShowLight;
                }
                else
                {
                    var version = GameVersion.None;
                    //Detect arrangement GameVersion
                    if (xmlSong != null && xmlSong.Version != null)
                    {
                        var verAttrib = Convert.ToInt32(xmlSong.Version);
                        if (verAttrib <= 6)
                        {
                            version = GameVersion.RS2012;
                        }
                        else if (verAttrib >= 7)
                        {
                            version = GameVersion.RS2014;
                        }
                    }
                    else
                    {
                        switch (currentGameVersion)
                        {
                        case GameVersion.RS2012:
                            // add missing XML elements
                            xmlSong.Version = "4";
                            xmlSong.Tuning  = new TuningStrings {
                                String0 = 0, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0
                            };
                            xmlSong.ArrangementProperties = new SongArrangementProperties2014 {
                                StandardTuning = 1
                            };
                            version = GameVersion.RS2012;
                            break;

                        case GameVersion.None:
                            using (var obj = new Rs1Converter())
                            {
                                xmlSong = null;
                                xmlSong = obj.SongToSong2014(Song.LoadFromFile(XmlFilePath.Text));
                            }
                            currentGameVersion = GameVersion.RS2014;
                            break;

                        default:
                            MessageBox.Show("Your version of EOF may be out of date, please update.", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            break;
                        }
                    }

                    // TODO: fix error checking logic for new types of conversion
                    if (currentGameVersion != version && version != GameVersion.None)
                    {
                        Debug.WriteLine("Please choose valid Rocksmith {0} arrangement file!", currentGameVersion);
                        //XmlFilePath.Text = "";
                        //return;
                    }

                    // SONG AND ARRANGEMENT INFO / ROUTE MASK
                    BonusCheckBox.Checked = Equals(xmlSong.ArrangementProperties.BonusArr, 1);
                    MetronomeCb.Checked   = Equals(xmlSong.ArrangementProperties.Metronome, 2);
                    if (!EditMode)
                    {
                        string arr = xmlSong.Arrangement.ToLowerInvariant();
                        if (arr.Contains("guitar") || arr.Contains("lead") || arr.Contains("rhythm") || arr.Contains("combo"))
                        {
                            arrangementTypeCombo.SelectedItem = ArrangementType.Guitar;

                            if (arr.Contains("combo"))
                            {
                                arrangementNameCombo.SelectedItem = ArrangementName.Combo;
                                if (currentGameVersion != GameVersion.RS2012)
                                {
                                    RouteMask = RouteMask.Lead;
                                }
                            }
                            else if (arr.Contains("guitar_22") || arr.Contains("lead") || Equals(xmlSong.ArrangementProperties.PathLead, 1))
                            {
                                arrangementNameCombo.SelectedItem = ArrangementName.Lead;
                                if (currentGameVersion != GameVersion.RS2012)
                                {
                                    RouteMask = RouteMask.Lead;
                                }
                            }
                            else if (arr.Contains("guitar") || arr.Contains("rhythm") || Equals(xmlSong.ArrangementProperties.PathRhythm, 1))
                            {
                                arrangementNameCombo.SelectedItem = ArrangementName.Rhythm;
                                if (currentGameVersion != GameVersion.RS2012)
                                {
                                    RouteMask = RouteMask.Rhythm;
                                }
                            }
                        }
                        else if (arr.Contains("bass"))
                        {
                            arrangementTypeCombo.SelectedItem = ArrangementType.Bass;
                            Picked.Checked = Equals(xmlSong.ArrangementProperties.BassPick, 1);

                            if (currentGameVersion != GameVersion.RS2012)
                            {
                                RouteMask = RouteMask.Bass;
                                //Low tuning fix for bass, If lowest string is B and bass fix not applied TODO:applyonly when 'generate'
                                if (xmlSong.Tuning.String0 < -4 && Arrangement.TuningPitch != 220)
                                {
                                    bassFix |= MessageBox.Show(@"The bass tuning may be too low.  Apply Low Bass Tuning Fix?" + Environment.NewLine +
                                                               @"Note: The fix will revert if bass arrangement is re-saved in EOF.  ",
                                                               @"Warning ... Low Bass Tuning", MessageBoxButtons.YesNo) == DialogResult.Yes;
                                }
                            }
                        }
                    }

                    if (currentGameVersion != GameVersion.RS2012)
                    {
                        //Tones setup //TODO: add parsing tones events
                        Arrangement.ToneBase        = xmlSong.ToneBase;
                        Arrangement.ToneA           = xmlSong.ToneA;
                        Arrangement.ToneB           = xmlSong.ToneB;
                        Arrangement.ToneC           = xmlSong.ToneC;
                        Arrangement.ToneD           = xmlSong.ToneD;
                        Arrangement.ToneMultiplayer = null;
                        SetupTones(Arrangement);

                        // Fix Low Bass Tuning
                        if (bassFix)
                        {
                            bassFix = false;
                            Arrangement.SongXml.File = XmlFilePath.Text;

                            if (Arrangement.TuningStrings == null)
                            {
                                // need to load tuning here from the xml arrangement
                                Arrangement.TuningStrings = new TuningStrings();
                                Arrangement.TuningStrings = xmlSong.Tuning;
                            }

                            if (!TuningFrequency.ApplyBassFix(Arrangement))
                            {
                                MessageBox.Show("This bass arrangement is already at 220Hz pitch.  ", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else
                            {
                                var commentsList = Arrangement.XmlComments.ToList();
                                commentsList.Add(new XComment("Low Bass Tuning Fixed"));
                                Arrangement.XmlComments = commentsList;
                            }

                            xmlSong.Tuning = Arrangement.TuningStrings;
                        }
                    }

                    // Setup tuning
                    ArrangementType selectedType;
                    if (xmlSong.Arrangement.ToLower() == "bass")
                    {
                        selectedType = ArrangementType.Bass;
                    }
                    else
                    {
                        selectedType = ArrangementType.Guitar;
                    }

                    FillTuningCombo(selectedType, currentGameVersion);

                    // find tuning in tuningComboBox list and make selection
                    int foundTuning = -1;
                    for (int tcbIndex = 0; tcbIndex < tuningComboBox.Items.Count; tcbIndex++)
                    {
                        tuningComboBox.SelectedIndex = tcbIndex;
                        TuningDefinition tuning = (TuningDefinition)tuningComboBox.Items[tcbIndex];
                        if (tuning.Tuning == xmlSong.Tuning)
                        {
                            foundTuning = tcbIndex;
                            break;
                        }
                    }

                    if (foundTuning == -1 && selectedType != ArrangementType.Bass)
                    {
                        tuningComboBox.SelectedIndex = 0;
                        ShowTuningForm(selectedType, new TuningDefinition(xmlSong.Tuning, currentGameVersion)); //FIXME: Don't use this for QuickAdd call
                    }

                    // E Standard, Drop D, and Open E tuning are now the same for both guitar and bass
                    if (foundTuning == -1 && selectedType == ArrangementType.Bass)
                    {
                        tuningComboBox.SelectedIndex = 0;
                        MessageBox.Show("Toolkit was not able to automatically set tuning for" + Environment.NewLine +
                                        "Bass Arrangement: " + Path.GetFileName(xmlFilePath) + Environment.NewLine +
                                        "Use the tuning selector dropdown or Tuning Editor" + Environment.NewLine +
                                        "to customize bass tuning (as defined for six strings).  ", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    tuningComboBox.Refresh();
                    Arrangement.Tuning        = tuningComboBox.SelectedItem.ToString();
                    Arrangement.TuningStrings = xmlSong.Tuning;
                    Arrangement.CapoFret      = xmlSong.Capo;
                    frequencyTB.Text          = Arrangement.TuningPitch.ToString(CultureInfo.InvariantCulture);

                    // bastard bass hack
                    if (Arrangement.Tuning.ToLower().Contains("fixed"))
                    {
                        frequencyTB.Text = "220";
                    }

                    //UpdateCentOffset();//bad way to update tuning info, IMO

                    // save converted RS1 to RS2014 Song2014 XML
                    if (version == GameVersion.None)
                    {
                        var srcDir        = Path.GetDirectoryName(XmlFilePath.Text);
                        var srcName       = Path.GetFileNameWithoutExtension(XmlFilePath.Text);
                        var backupSrcPath = String.Format("{0}_{1}.xml", Path.Combine(srcDir, srcName), "RS1");

                        // backup original RS1 file
                        File.Copy(XmlFilePath.Text, backupSrcPath);

                        // write converted RS1 file
                        using (var stream = new FileStream(XmlFilePath.Text, FileMode.Create))
                            xmlSong.Serialize(stream, true);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(@"Unable to get information from XML arrangement:  " + Environment.NewLine +
                                Path.GetFileName(xmlFilePath) + Environment.NewLine +
                                @"It may not be a valid arrangement or " + Environment.NewLine +
                                @"your version of the EOF may be out of date." + Environment.NewLine +
                                ex.Message, DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            return(true);
        }
Beispiel #8
0
        // only for RS2014
        public static bool ApplyBassFix(Arrangement arr, bool saveTuningDefinition = false)
        {
            var debubMe = arr;

            // get the latest comments from the XML
            var xmlComments = Song2014.ReadXmlComments(arr.SongXml.File);
            var isBassFixed = xmlComments.Any(xComment => xComment.ToString().Contains("Low Bass Tuning Fixed")) || arr.TuningPitch.Equals(220.0);

            if (isBassFixed)
            {
                Debug.WriteLine("Low bass tuning may already be fixed: " + arr.SongXml.File);
                // return false;
            }

            // TODO: check guitar compatibility
            // Octave up for each string
            Int16[] strings = arr.TuningStrings.ToArray();
            for (int s = 0; s < strings.Length; s++)
            {
                if (strings[s] < 0)
                {
                    strings[s] += 12;
                }
            }

            // update XML arrangement
            Song2014 songXml = Song2014.LoadFromFile(arr.SongXml.File);

            songXml.CentOffset = "-1200.0"; // Force 220Hz
            songXml.Tuning     = new TuningStrings(strings);

            // bass tuning definition gets auto added/saved to repository
            if (saveTuningDefinition)
            {
                var tuningDef = TuningDefinitionRepository.Instance.Detect(songXml.Tuning, GameVersion.RS2014, false);

                if (!tuningDef.Name.Contains("Fixed"))
                {
                    var tuningUiName = String.Format("{0} Fixed", tuningDef.UIName);
                    var bassTuning   = new TuningDefinition
                    {
                        Custom      = true,
                        GameVersion = GameVersion.RS2014,
                        Name        = tuningUiName.Replace(" ", ""),
                        Tuning      = songXml.Tuning,
                        UIName      = tuningUiName
                    };

                    TuningDefinitionRepository.SaveUnique(bassTuning);
                }
            }

            using (var stream = File.Open(arr.SongXml.File, FileMode.Create))
                songXml.Serialize(stream, true);

            // write xml comments back to fixed bass arrangement
            if (!isBassFixed)
            {
                Song2014.WriteXmlComments(arr.SongXml.File, xmlComments, customComment: "Low Bass Tuning Fixed");
            }

            return(true);
        }
        private void songXmlBrowseButton_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter = "Rocksmith Song Xml Files (*.xml)|*.xml";
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                if (isAlreadyAdded(ofd.FileName))
                {
                    MessageBox.Show("This arrangement already added, please choose another one. ", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                XmlFilePath.Text = ofd.FileName;
            }

            string xmlFilePath = XmlFilePath.Text;

            try
            {
                bool isVocal = false;
                try
                {
                    xmlSong = Song2014.LoadFromFile(xmlFilePath);
                    Arrangement.XmlComments = Song2014.ReadXmlComments(xmlFilePath);
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.Message.ToLower().Contains("<vocals"))
                    {
                        isVocal = true;
                    }
                    else
                    {
                        MessageBox.Show("Unable to get information from the arrangement XML. \nYour version of the EoF is up to date? \n" + ex.Message, DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }

                // SETUP FIELDS
                if (isVocal)
                {
                    arrangementTypeCombo.SelectedItem = ArrangementType.Vocal;
                }
                else
                {
                    var version = GameVersion.None;
                    //Detect arrangement GameVersion
                    if (xmlSong != null && xmlSong.Version != null)
                    {
                        var verAttrib = Convert.ToInt32(xmlSong.Version);
                        if (verAttrib <= 6)
                        {
                            version = GameVersion.RS2012;
                        }
                        else if (verAttrib >= 7)
                        {
                            version = GameVersion.RS2014;
                        }
                    }
                    else if (currentGameVersion == GameVersion.RS2012)
                    {
                        // add missing XML elements
                        xmlSong.Version = "4";
                        xmlSong.Tuning  = new TuningStrings {
                            String0 = 0, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0
                        };
                        xmlSong.ArrangementProperties = new SongArrangementProperties2014 {
                            StandardTuning = 1
                        };
                        version = GameVersion.RS2012;
                    }
                    else if (currentGameVersion == GameVersion.None)
                    {
                        using (var obj = new Rs1Converter())
                        {
                            xmlSong = null;
                            xmlSong = obj.SongToSong2014(Song.LoadFromFile(XmlFilePath.Text));
                        }
                        currentGameVersion = GameVersion.RS2014;
                    }
                    else
                    {
                        MessageBox.Show("You are using a old version of EoF application, please update first.", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    // TODO: fix error checking logic for new types of conversion
                    if (currentGameVersion != version && version != GameVersion.None)
                    {
                        Debug.WriteLine(String.Format("Please choose valid Rocksmith {0} arrangement file!", currentGameVersion));
                        //XmlFilePath.Text = "";
                        //return;
                    }

                    // SONG AND ARRANGEMENT INFO / ROUTE MASK
                    BonusCheckBox.Checked = Equals(xmlSong.ArrangementProperties.BonusArr, 1);
                    MetronomeCb.Checked   = Equals(xmlSong.ArrangementProperties.Metronome, 2);
                    if (!EditMode)
                    {
                        string arr = xmlSong.Arrangement.ToLowerInvariant();
                        if (arr.Contains("guitar") || arr.Contains("lead") || arr.Contains("rhythm") || arr.Contains("combo"))
                        {
                            arrangementTypeCombo.SelectedItem = ArrangementType.Guitar;

                            if (arr.Contains("combo"))
                            {
                                arrangementNameCombo.SelectedItem = ArrangementName.Combo;
                                if (currentGameVersion != GameVersion.RS2012)
                                {
                                    RouteMask = RouteMask.Lead;
                                }
                            }
                            else if (arr.Contains("guitar_22") || arr.Contains("lead") || Equals(xmlSong.ArrangementProperties.PathLead, 1))
                            {
                                arrangementNameCombo.SelectedItem = ArrangementName.Lead;
                                if (currentGameVersion != GameVersion.RS2012)
                                {
                                    RouteMask = RouteMask.Lead;
                                }
                            }
                            else if (arr.Contains("guitar") || arr.Contains("rhythm") || Equals(xmlSong.ArrangementProperties.PathRhythm, 1))
                            {
                                arrangementNameCombo.SelectedItem = ArrangementName.Rhythm;
                                if (currentGameVersion != GameVersion.RS2012)
                                {
                                    RouteMask = RouteMask.Rhythm;
                                }
                            }
                        }
                        else if (arr.Contains("bass"))
                        {
                            arrangementTypeCombo.SelectedItem = ArrangementType.Bass;

                            //SetTuningCombo(xmlSong.Tuning, true);
                            Picked.Checked = Equals(xmlSong.ArrangementProperties.BassPick, 1);
                            if (currentGameVersion != GameVersion.RS2012)
                            {
                                RouteMask = RouteMask.Bass;
                                //Low tuning fix for bass, If lowstring is B and bass fix not applied
                                if (xmlSong.Tuning.String0 < -4 && this.frequencyTB.Text == "440")
                                {
                                    bassFix |= MessageBox.Show("Your tuning is too low, would you like to apply \"Low Tuning Fix?\"\n" + "Note, that this won't work if you re-save arangement in EOF.\n", "Low Tuning Fix Required!", MessageBoxButtons.YesNo) == DialogResult.Yes;
                                }
                            }
                        }
                    }

                    //Tones setup
                    if (currentGameVersion != GameVersion.RS2012)
                    {
                        Arrangement.ToneBase        = xmlSong.ToneBase;
                        Arrangement.ToneA           = xmlSong.ToneA;
                        Arrangement.ToneB           = xmlSong.ToneB;
                        Arrangement.ToneC           = xmlSong.ToneC;
                        Arrangement.ToneD           = xmlSong.ToneD;
                        Arrangement.ToneMultiplayer = null;

                        SetupTones(Arrangement);

                        //Apply bass Fix, refactor me.
                        if (bassFix)
                        {
                            bassFix = false;
                            Arrangement.SongXml.File = XmlFilePath.Text;
                            parentControl.ApplyBassFix(Arrangement);
                        }
                    }

                    // Setup tuning
                    var selectedType = new ArrangementType();
                    if (xmlSong.Arrangement.ToLower() == "bass")
                    {
                        selectedType = ArrangementType.Bass;
                    }
                    else
                    {
                        selectedType = ArrangementType.Guitar;
                    }

                    FillTuningCombo(selectedType, currentGameVersion);

                    // find tuning in tuningComboBox list and make selection
                    int foundTuning = -1;
                    for (int tcbIndex = 0; tcbIndex < tuningComboBox.Items.Count; tcbIndex++)
                    {
                        tuningComboBox.SelectedIndex = tcbIndex;
                        TuningDefinition tuning = (TuningDefinition)tuningComboBox.Items[tcbIndex];
                        if (TuningDefinition.TuningEquals(tuning.Tuning, xmlSong.Tuning))
                        {
                            foundTuning = tcbIndex;
                            break;
                        }
                    }

                    if (foundTuning == -1)
                    {
                        ShowTuningForm(selectedType, new TuningDefinition()
                        {
                            Tuning = xmlSong.Tuning, Custom = true, GameVersion = currentGameVersion
                        });
                    }
                    else
                    {
                        tuningComboBox.SelectedIndex = foundTuning;
                    }

                    tuningComboBox.Refresh();

                    Arrangement.Tuning        = tuningComboBox.SelectedItem.ToString();
                    Arrangement.TuningStrings = xmlSong.Tuning;
                    Arrangement.CapoFret      = xmlSong.Capo;
                    frequencyTB.Text          = Arrangement.TuningPitch.ToString();
                    UpdateCentOffset();

                    // save converted RS1 to RS2014 Song2014 XML
                    if (version == GameVersion.None)
                    {
                        var srcDir        = Path.GetDirectoryName(XmlFilePath.Text);
                        var srcName       = Path.GetFileNameWithoutExtension(XmlFilePath.Text);
                        var backupSrcPath = String.Format("{0}_{1}.xml", Path.Combine(srcDir, srcName), "RS1");

                        // backup original RS1 file
                        File.Copy(XmlFilePath.Text, backupSrcPath);

                        // write converted RS1 file
                        using (FileStream stream = new FileStream(XmlFilePath.Text, FileMode.Create))
                            xmlSong.Serialize(stream, true);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to get information from the arrangement XML. \nYour version of the EoF is up to date? \n" + ex.Message,
                                DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }