public static Sng2014File ConvertXML(string xmlPath, ArrangementType type, string cdata = null)
 {
     if (type == ArrangementType.Vocal) {
         return Sng2014FileWriter.ReadVocals(xmlPath, cdata);
     }
     return Sng2014File.ConvertSong(xmlPath);
 }
        public static void Write(string inputFile, string outputFile, ArrangementType arrangementType, Platform platform)
        {
            using (var reader = new StreamReader(inputFile))
            {
                var bitConverter = platform.GetBitConverter;
                if (arrangementType == ArrangementType.Vocal)
                {
                    var serializer = new XmlSerializer(typeof(Vocals));
                    var vocals = (Vocals)serializer.Deserialize(reader);
                    WriteRocksmithVocalsFile(vocals, outputFile, bitConverter);
                }
                else
                {
                    var serializer = new XmlSerializer(typeof(Song));
                    var song = (Song)serializer.Deserialize(reader);

                    // TODO: song.Tuning is null in toolkit generated RS1 Xml files
                    // TODO: this is only a quick fix of the root problem
                    var tuning = new Int16[] { 0, 0, 0, 0, 0, 0 };
                    if (song.Tuning != null) tuning = song.Tuning.ToArray();

                    WriteRocksmithSngFile(song, InstrumentTuningExtensions.GetTuningByOffsets(tuning), arrangementType, outputFile, bitConverter);

                }
            }
        }
        public static void Write(string inputFile, string outputFile, ArrangementType arrangementType, Platform platform)
        {
            using (var reader = new StreamReader(inputFile))
            {
                var bitConverter = platform.GetBitConverter;
                if (arrangementType == ArrangementType.Vocal)
                {
                    var serializer = new XmlSerializer(typeof(Vocals));
                    var vocals     = (Vocals)serializer.Deserialize(reader);
                    WriteRocksmithVocalsFile(vocals, outputFile, bitConverter);
                }
                else
                {
                    var serializer = new XmlSerializer(typeof(Song));
                    var song       = (Song)serializer.Deserialize(reader);

                    // TODO: song.Tuning is null in toolkit generated RS1 Xml files
                    // HACK: this is only a quick fix of the root problem
                    var tuning = new Int16[] { 0, 0, 0, 0, 0, 0 };
                    if (song.Tuning != null)
                    {
                        tuning = song.Tuning.ToArray();
                    }

                    WriteRocksmithSngFile(song, InstrumentTuningExtensions.GetTuningByOffsets(tuning), arrangementType, outputFile, bitConverter);
                }
            }
        }
        /// <summary>
        /// WARNING: This method may not detect the Arrangment Tuning correctly
        /// <para>Use the Write(Arrangement arr, string outputFile, Platform platform) method to detect tuning correctly ...</para>
        /// </summary>
        // [Obsolete("Deprecated, please use Write(Arrangement arr, string outputFile, Platform platform) method.", false)]
        public static void Write(string inputFile, string outputFile, ArrangementType arrangementType, Platform platform)
        {
            using (var reader = new StreamReader(inputFile))
            {
                var bitConverter = platform.GetBitConverter;
                if (arrangementType == ArrangementType.Vocal)
                {
                    var serializer = new XmlSerializer(typeof(Vocals));
                    var vocals     = (Vocals)serializer.Deserialize(reader);
                    WriteVocalsFile(vocals, outputFile, bitConverter);
                }
                else
                {
                    var serializer = new XmlSerializer(typeof(Song));
                    var song       = (Song)serializer.Deserialize(reader);

                    // HACK: apply Standard E tuning
                    var tuning = new Int16[] { 0, 0, 0, 0, 0, 0 };
                    if (song.Tuning != null)
                    {
                        tuning = song.Tuning.ToArray();
                    }
                    else
                    {
                        var diaMsg = "<WARNING> Arrangement XML contains no tuning element ..." + Environment.NewLine +
                                     "The arrangment will be defaulted to Standard E tuning.";
                        MessageBox.Show(diaMsg, "SngFileWriter Null Tuning ...");
                    }

                    WriteSngFile(song, InstrumentTuningExtensions.GetTuningByOffsets(tuning), arrangementType, outputFile, bitConverter);
                }
            }
        }
Beispiel #5
0
        public int GetSongPartition(ArrangementName arrangementName, ArrangementType arrangementType)
        {
            switch (arrangementType)
            {
            case Sng.ArrangementType.Bass:
                songPartitionCount[3]++;
                return(songPartitionCount[3]);

            default:
                switch (arrangementName)
                {
                case RocksmithToolkitLib.Sng.ArrangementName.Lead:
                    songPartitionCount[1]++;
                    return(songPartitionCount[1]);

                case RocksmithToolkitLib.Sng.ArrangementName.Rhythm:
                    songPartitionCount[2]++;
                    return(songPartitionCount[2]);

                default:
                    songPartitionCount[0]++;
                    return(songPartitionCount[0]);
                }
            }
            ;
        }
Beispiel #6
0
        public static void Write(string inputFile, string outputFile, ArrangementType arrangementType, Platform platform)
        {
            using (var reader = new StreamReader(inputFile))
            {
                var bitConverter = platform.GetBitConverter;
                if (arrangementType == ArrangementType.Vocal)
                {
                    var serializer = new XmlSerializer(typeof(Vocals));
                    var vocals     = (Vocals)serializer.Deserialize(reader);
                    WriteVocalsFile(vocals, outputFile, bitConverter);
                }
                else
                {
                    var serializer = new XmlSerializer(typeof(Song));
                    var song       = (Song)serializer.Deserialize(reader);

                    // TODO: song.Tuning is null (does not exist in the XML Arrangement)
                    // HACK: apply Standard E tuning
                    var tuning = new Int16[] { 0, 0, 0, 0, 0, 0 };
                    if (song.Tuning != null)
                    {
                        tuning = song.Tuning.ToArray();
                    }
                    else
                    {
                        throw new DataException("<ERROR> Arrangement XML contains no tuning element" + Environment.NewLine +
                                                "The arrangment will be defaulted to Standard E tuning" + Environment.NewLine);
                    }

                    WriteSngFile(song, InstrumentTuningExtensions.GetTuningByOffsets(tuning), arrangementType, outputFile, bitConverter);
                }
            }
        }
Beispiel #7
0
        public int GetSongPartition(ArrangementName arrangementName, ArrangementType arrangementType)
        {
            switch (arrangementType)
            {
            case ArrangementType.Bass:
                songPartitionCount[3]++;
                return(songPartitionCount[3]);

            default:
                switch (arrangementName)
                {
                case ArrangementName.Lead:
                    songPartitionCount[1]++;
                    return(songPartitionCount[1]);

                case ArrangementName.Rhythm:
                    songPartitionCount[2]++;
                    return(songPartitionCount[2]);

                default:         //Combo
                    songPartitionCount[0]++;
                    return(songPartitionCount[0]);
                }
            }
        }
Beispiel #8
0
        private static void ArrangeAsGrid(float spacing = 1, int columnCount = 0, ArrangementType arrangementType = ArrangementType.Vertical)
        {
            var sel = SelectionOrderedBySiblingIndex();

            if (columnCount <= 0)
            {
                columnCount = Mathf.FloorToInt(Mathf.Sqrt(sel.Length));
            }

            for (var index = 0; index < sel.Length; index++)
            {
                var obj = sel[index];

                var column = index % columnCount;
                var row    = Mathf.FloorToInt((float)index / columnCount);

                switch (arrangementType)
                {
                case ArrangementType.Vertical:
                    obj.transform.position = new Vector3(column * spacing, row * spacing, 0);
                    break;

                case ArrangementType.Ground:
                    obj.transform.position = new Vector3(column * spacing, 0, row * spacing);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(arrangementType), arrangementType, null);
                }
            }
        }
 public static Sng2014File ConvertXML(string xmlPath, ArrangementType type)
 {
     if (type != ArrangementType.Vocal) {
         return Sng2014File.ConvertSong(xmlPath);
     } else {
         return Sng2014FileWriter.ReadVocals(xmlPath);
     }
 }
Beispiel #10
0
        private int AddLineInternal(ArrangementType arrType, int minHeight, int maxHeight)
        {
            var elem = new GridLine(this, arrType, minHeight);

            elem.prefValue = maxHeight;
            elementList.Add(elem);
            return(elementList.Count - 1);
        }
        public static int GetMidiNote(this InstrumentTuning tuning, ArrangementType arrangementType, int stringNumber, int fret)
        {
            if (fret == -1) return -1;
            var strNote = StandardMidiNotes[stringNumber] + tuning.GetOffsets()[stringNumber];
            strNote -= arrangementType == ArrangementType.Bass ? 12 : 0;

            return strNote + fret;
        }
Beispiel #12
0
 public static Sng2014File ConvertXML(string xmlPath, ArrangementType type, string cdata = null)
 {
     if (type == ArrangementType.Vocal)
     {
         return(Sng2014FileWriter.ReadVocals(xmlPath, cdata));
     }
     return(Sng2014File.ConvertSong(xmlPath));
 }
 public string GetArrangementFileName(ArrangementName arrangementName, ArrangementType arrangementType)
 {
     if(arrangementType == ArrangementType.Vocal) return "vocals";
     var name = arrangementName.ToString();
     var count = GetSongPartition(arrangementName, arrangementType);
     if (count > 1)
         name += count.ToString();
     return name;
 }
Beispiel #14
0
 public static Sng2014File ConvertXML(string xmlPath, ArrangementType type)
 {
     if (type != ArrangementType.Vocal)
     {
         return(Sng2014File.ConvertSong(xmlPath));
     }
     else
     {
         return(Sng2014FileWriter.ReadVocals(xmlPath));
     }
 }
        public static int GetMidiNote(this InstrumentTuning tuning, ArrangementType arrangementType, int stringNumber, int fret)
        {
            if (fret == -1)
            {
                return(-1);
            }
            var strNote = StandardMidiNotes[stringNumber] + tuning.GetOffsets()[stringNumber];

            strNote -= arrangementType == ArrangementType.Bass ? 12 : 0;

            return(strNote + fret);
        }
Beispiel #16
0
        private void UpdateRouteMaskPath(ArrangementType arrangementType, ArrangementName arrangementName)
        {
            gbGameplayPath.Enabled = (arrangementType != ArrangementType.Vocal && arrangementType != ArrangementType.ShowLight) && currentGameVersion != GameVersion.RS2012;

            //Enabling
            routeMaskLeadRadio.Enabled   = arrangementType == ArrangementType.Guitar && (arrangementName == ArrangementName.Combo || arrangementName == ArrangementName.Lead);
            routeMaskRhythmRadio.Enabled = arrangementType == ArrangementType.Guitar && (arrangementName == ArrangementName.Combo || arrangementName == ArrangementName.Rhythm);
            routeMaskBassRadio.Enabled   = arrangementType == ArrangementType.Bass;

            //Auto-checking
            routeMaskLeadRadio.Checked   = arrangementType == ArrangementType.Guitar && (arrangementName == ArrangementName.Combo || arrangementName == ArrangementName.Lead);
            routeMaskRhythmRadio.Checked = arrangementType == ArrangementType.Guitar && (arrangementName == ArrangementName.Combo || arrangementName == ArrangementName.Rhythm);
            routeMaskBassRadio.Checked   = arrangementType == ArrangementType.Bass;
        }
 public Reservation(Customer customer, DateTime reservationCreated, Address limousineExpectedAddress, Location startLocation, Location arrivalLocation,
                    ArrangementType arrangementType, DateTime startTime, DateTime endTime, TimeSpan totalHours, Limousine limousine, Price price)
 {
     Customer                 = customer;
     ReservationCreated       = reservationCreated;
     LimousineExpectedAddress = limousineExpectedAddress;
     StartLocation            = startLocation;
     ArrivalLocation          = arrivalLocation;
     ArrangementType          = arrangementType;
     StartTime                = startTime;
     EndTime    = endTime;
     TotalHours = totalHours;
     Limousine  = limousine;
     Price      = price;
 }
Beispiel #18
0
        public string GetArrangementFileName(ArrangementName arrangementName, ArrangementType arrangementType)
        {
            if (arrangementType == ArrangementType.Vocal)
            {
                return("vocals");
            }
            var name  = arrangementName.ToString();
            var count = GetSongPartition(arrangementName, arrangementType);

            if (count > 1)
            {
                name += count.ToString();
            }
            return(name);
        }
Beispiel #19
0
        private void AddElementInternal(int line, Control child, ArrangementType arrType, int minWidth, int maxWidth)
        {
            LayoutElement element = null;

            if (child == null)
            {
                element = new BlankElement(arrType, minWidth);
            }
            else
            {
                parent.Controls.Add(child);
                element = new GridElement(this, child, arrType, minWidth);
            }
            element.prefValue = maxWidth;
            elementList[line].AddElement(element);
        }
Beispiel #20
0
        private void FillTuningCombo(ArrangementType arrangementType, GameVersion gameVersion)
        {
            tuningComboBox.Items.Clear();
            var tuningDefinitions = TuningDefinitionRepository.LoadTuningDefinitions(gameVersion);

            // LINQ method produces unexpected results on subsequent calls
            // foreach (var tuning in TuningDefinitionRepository.Instance().Select(gameVersion))
            foreach (var tuning in tuningDefinitions)
            {
                // need to populate for Vocals too even though not used
                //if (arrangementType != ArrangementType.Bass)
                tuningComboBox.Items.Add(tuning);
                //if (arrangementType == ArrangementType.Bass)
                // tuningComboBox.Items.Add(TuningDefinition.Convert2Bass(tuning));
            }

            tuningComboBox.SelectedIndex = 0;
            tuningComboBox.Refresh();
        }
 public int GetSongPartition(ArrangementName arrangementName, ArrangementType arrangementType)
 {
     switch (arrangementType)
     {
         case Sng.ArrangementType.Bass:
             songPartitionCount[3]++;
             return songPartitionCount[3];
         default:
             switch (arrangementName)
             {
                 case RocksmithToolkitLib.Sng.ArrangementName.Lead:
                     songPartitionCount[1]++;
                     return songPartitionCount[1];
                 case RocksmithToolkitLib.Sng.ArrangementName.Rhythm:
                     songPartitionCount[2]++;
                     return songPartitionCount[2];
                 default:
                     songPartitionCount[0]++;
                     return songPartitionCount[0];
             }
     };
 }
Beispiel #22
0
        private void FillTuningCombo(ArrangementType arrangementType, GameVersion gameVersion)
        {
            tuningComboBox.Items.Clear();

            // TODO: figure out logic behind unexpected LINQ behaviors
            // tuningComboBox list is being updated with custom tuning info
            // so refilling the combo-box is required to produce the expected results
            // for now using old fashioned non-LINQ method
            var tuningDefinitions = TuningDefinitionRepository.Instance.LoadTuningDefinitions(gameVersion);

            foreach (var tuning in tuningDefinitions) //also add tuning from songXml used
            {
                // need to populate for Vocals too even though not used
                //if (arrangementType != ArrangementType.Bass)
                tuningComboBox.Items.Add(tuning);
                //if (arrangementType == ArrangementType.Bass)
                // tuningComboBox.Items.Add(TuningDefinition.Convert2Bass(tuning));
            }

            tuningComboBox.SelectedIndex = 0;
            tuningComboBox.Refresh();
        }
Beispiel #23
0
        public static void Write(string inputFile, string outputFile, ArrangementType arrangementType, Platform platform)
        {
            using (var reader = new StreamReader(inputFile))
            {
                var bitConverter = platform.platform == GamePlatform.Pc
                    ? (EndianBitConverter)EndianBitConverter.Little
                    : (EndianBitConverter)EndianBitConverter.Big;

                if (arrangementType == ArrangementType.Vocal)
                {
                    var serializer = new XmlSerializer(typeof(Vocals));
                    var vocals     = (Vocals)serializer.Deserialize(reader);
                    WriteRocksmithVocalsFile(vocals, outputFile, bitConverter);
                }
                else
                {
                    var serializer = new XmlSerializer(typeof(Song));
                    var song       = (Song)serializer.Deserialize(reader);
                    WriteRocksmithSngFile(song, InstrumentTuningExtensions.GetTuningByOffsets(song.Tuning.ToArray()), arrangementType, outputFile, bitConverter);
                }
            }
        }
        public ActionResult Save(ArrangementType arrangementType)
        {
            if (!ModelState.IsValid)
            {
                return(View("ArrangementTypeTableForm", arrangementType));
            }

            if (arrangementType.Id == 0)
            {
                _context.ArrangementTypes.Add(arrangementType);
            }
            else
            {
                var arrangementTypeInDb = _context.ArrangementTypes.Single(d => d.Id == arrangementType.Id);

                arrangementTypeInDb.Name = arrangementType.Name;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "ArrangementTypeTable"));
        }
        private void FillTuningCombo(ArrangementType arrangementType, GameVersion gameVersion)
        {
            tuningComboBox.Items.Clear();
            var tuningDefinitions = TuningDefinitionRepository.LoadTuningDefinitions(gameVersion);

            // LINQ method produces unexpected results on subsequent calls
            // foreach (var tuning in TuningDefinitionRepository.Instance().Select(gameVersion))
            foreach (var tuning in tuningDefinitions)
            {
                if (arrangementType == ArrangementType.Guitar)
                {
                    tuningComboBox.Items.Add(tuning);
                }
                if (arrangementType == ArrangementType.Bass)
                {
                    tuningComboBox.Items.Add(TuningDefinition.Convert2Bass(tuning));
                }
            }

            tuningComboBox.SelectedIndex = 0;
            tuningComboBox.Refresh();
        }
 public int GetSongPartition(ArrangementName arrangementName, ArrangementType arrangementType)
 {
     switch (arrangementType)
     {
         case ArrangementType.Bass:
             songPartitionCount[3]++;
             return songPartitionCount[3];
         default:
             switch (arrangementName)
             {
                 case ArrangementName.Lead:
                     songPartitionCount[1]++;
                     return songPartitionCount[1];
                 case ArrangementName.Rhythm:
                     songPartitionCount[2]++;
                     return songPartitionCount[2];
                 default: //Combo
                     songPartitionCount[0]++;
                     return songPartitionCount[0];
             }
     }
 }
        /// <summary>
        /// The get binary characteristic types.
        /// </summary>
        /// <returns>
        /// The <see cref="List{CharacteristicData}"/>.
        /// </returns>
        public List <CharacteristicSelectListItem> GetCharacteristicTypes()
        {
            Link[] links;
            BinaryCharacteristic[] characteristics;
            ArrangementType        arrangementType = ArrangementType.Intervals;

            if (AccountHelper.IsAdmin())
            {
                links           = EnumExtensions.ToArray <Link>();
                characteristics = EnumExtensions.ToArray <BinaryCharacteristic>();
            }
            else
            {
                links           = Aliases.UserAvailableLinks.ToArray();
                characteristics = Aliases.UserAvailableBinaryCharacteristics.ToArray();
            }

            var result = new List <CharacteristicSelectListItem>(characteristics.Length);

            foreach (BinaryCharacteristic characteristic in characteristics)
            {
                List <SelectListItem> linkSelectListItems = characteristicsLinks
                                                            .Where(cl => cl.BinaryCharacteristic == characteristic && links.Contains(cl.Link))
                                                            .Select(cl => new SelectListItem {
                    Value = ((byte)cl.Link).ToString(), Text = cl.Link.GetDisplayValue()
                })
                                                            .ToList();
                var arrangementTypeSelectListItems = new List <SelectListItem>
                {
                    new SelectListItem {
                        Value = ((byte)arrangementType).ToString(), Text = arrangementType.GetDisplayValue()
                    }
                };
                result.Add(new CharacteristicSelectListItem((byte)characteristic, characteristic.GetDisplayValue(), linkSelectListItems, arrangementTypeSelectListItems));
            }

            return(result);
        }
        /// <summary>
        /// Geef een lijst van limousines op basis van het arrangement, indien de prijs niet 0 is
        /// </summary>
        public List <Limousine> FindAllAvailable(ArrangementType arrangement)
        {
            List <Limousine> limousines = new List <Limousine>();

            if (arrangement == ArrangementType.Wedding)
            {
                limousines = context.Limousines.Where(l => l.WeddingPrice != 0).ToList();
            }
            else if (arrangement == ArrangementType.Wellness)
            {
                limousines = context.Limousines.Where(l => l.WelnessPrice != 0).ToList();
            }
            else if (arrangement == ArrangementType.NightLife)
            {
                limousines = context.Limousines.Where(l => l.NightLifePrice != 0).ToList();
            }
            else
            {
                limousines = context.Limousines.ToList();
            }

            return(limousines);
        }
        private void FillTuningCombo(ArrangementType arrangementType, GameVersion gameVersion)
        {
            tuningComboBox.Items.Clear();

            // TODO: figure out logic behind unexpected LINQ behaviors
            // tuningComboBox list is being updated with custom tuning info
            // so refilling the combo-box is required to produce the expected results
            // for now using old fashioned non-LINQ method
            var tuningDefinitions = TuningDefinitionRepository.Instance.LoadTuningDefinitions(gameVersion);
            foreach (var tuning in tuningDefinitions) //also add tuning from songXml used
            {
                // need to populate for Vocals too even though not used
                //if (arrangementType != ArrangementType.Bass)
                tuningComboBox.Items.Add(tuning);
                //if (arrangementType == ArrangementType.Bass)
                // tuningComboBox.Items.Add(TuningDefinition.Convert2Bass(tuning));
            }

            tuningComboBox.SelectedIndex = 0;
            tuningComboBox.Refresh();
        }
        public ActionResult New()
        {
            var arrangementType = new ArrangementType();

            return(View("ArrangementTypeTableForm", arrangementType));
        }
        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)
                        ShowTuningForm(selectedType, new TuningDefinition { Tuning = xmlSong.Tuning, Custom = true, GameVersion = currentGameVersion });
                    else
                    {
                        if (selectedType == ArrangementType.Bass)
                        {
                            MessageBox.Show(@"Remember to set the correct tuning using Edit for" + Environment.NewLine +
                                @"Bass Arrangement: " + Path.GetFileName(xmlFilePath),
                                DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                            tuningComboBox.SelectedIndex = 0;
                        }
                        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 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;
        }
        private void UpdateRouteMaskPath(ArrangementType arrangementType, ArrangementName arrangementName)
        {
            gbGameplayPath.Enabled = (arrangementType != ArrangementType.Vocal && arrangementType != ArrangementType.ShowLight) && currentGameVersion != GameVersion.RS2012;

            //Enabling
            routeMaskLeadRadio.Enabled = arrangementType == ArrangementType.Guitar && (arrangementName == ArrangementName.Combo || arrangementName == ArrangementName.Lead);
            routeMaskRhythmRadio.Enabled = arrangementType == ArrangementType.Guitar && (arrangementName == ArrangementName.Combo || arrangementName == ArrangementName.Rhythm);
            routeMaskBassRadio.Enabled = arrangementType == ArrangementType.Bass;

            //Auto-checking
            routeMaskLeadRadio.Checked = arrangementType == ArrangementType.Guitar && (arrangementName == ArrangementName.Combo || arrangementName == ArrangementName.Lead);
            routeMaskRhythmRadio.Checked = arrangementType == ArrangementType.Guitar && (arrangementName == ArrangementName.Combo || arrangementName == ArrangementName.Rhythm);
            routeMaskBassRadio.Checked = arrangementType == ArrangementType.Bass;
        }
        // INCOMPLETE
        // section begins at @ 9,820 in NumberThirteen_Lead.sng
        private static void WriteRocksmithSngLevels(EndianBinaryWriter w, XML.SongLevel[] levels, Single songLength, List <PhraseIterationInfo> iterationInfo, ArrangementType arrangementType)
        {
            // output header
            if (levels == null || levels.Length == 0)
            {
                w.Write(new byte[4]); // empty header
                return;
            }

            // output header count
            w.Write(levels.Length);

            // output
            foreach (var level in levels)
            {
                // level difficulty tag
                w.Write(level.Difficulty);

                // anchors
                WriteRocksmithSngLevelAnchors(w, level.Anchors, level, iterationInfo, songLength);

                // slide properties
                WriteRockmithSngLevelSlideProperties(w, level.Notes);

                // handshapes
                WriteRocksmithSngLevelHandShapes(w, level.HandShapes, level, songLength);

                // notes and chords
                WriteRocksmithSngLevelNotes(w, iterationInfo, level.Notes, level.Chords, songLength, arrangementType);

                var iterationNotes = new List <int>();
                foreach (var iteration in iterationInfo)
                {
                    int num = 0;
                    if (level.Notes != null)
                    {
                        num += level.Notes.Count(n => n.Time >= iteration.StartTime && n.Time < iteration.EndTime);
                    }
                    if (level.Chords != null)
                    {
                        num += level.Chords.Count(n => n.Time >= iteration.StartTime && n.Time < iteration.EndTime);
                    }
                    iterationNotes.Add(num);
                }

                var phrases = iterationInfo.GroupBy(it => it.PhraseId).OrderBy(grp => grp.Key);
                // count of phrases
                w.Write(phrases.Count());
                foreach (var phrase in phrases)
                {
                    float notes = (float)phrase.Sum(iteration => iterationNotes[iteration.IterationId]);
                    float count = phrase.Count();

                    w.Write(notes / count); // This is the number of notes + chords in all iterations of this phrase for this level, divided by number of iterations of this phrase
                }

                // count of phrase iterations
                w.Write(iterationInfo.Count);
                foreach (var iterationNoteCount in iterationNotes)
                {
                    w.Write(iterationNoteCount);// This appears to be the number of notes + chords in each iteration for this level
                }

                // count of phrase iterations
                w.Write(iterationInfo.Count);
                foreach (var iterationNoteCount in iterationNotes)
                {
                    w.Write(iterationNoteCount);// This appears to be the number of notes + chords in each iteration for this level
                }
            }
        }
        // COMPLETE
        private static void WriteRocksmithSngChordTemplates(EndianBinaryWriter w, SongChordTemplate[] chordTemplates, InstrumentTuning tuning, ArrangementType arrangementType)
        {
            // output header
            if (chordTemplates == null || chordTemplates.Length == 0)
            {
                w.Write(new byte[4]); // empty header
                return;
            }

            // output header count
            w.Write(chordTemplates.Length);

            // output chord templates
            foreach (SongChordTemplate chordTemplate in chordTemplates)
            {
                // fret numbers
                w.Write(chordTemplate.Fret0);
                w.Write(chordTemplate.Fret1);
                w.Write(chordTemplate.Fret2);
                w.Write(chordTemplate.Fret3);
                w.Write(chordTemplate.Fret4);
                w.Write(chordTemplate.Fret5);

                // finger positions
                w.Write(chordTemplate.Finger0);
                w.Write(chordTemplate.Finger1);
                w.Write(chordTemplate.Finger2);
                w.Write(chordTemplate.Finger3);
                w.Write(chordTemplate.Finger4);
                w.Write(chordTemplate.Finger5);

                // note values
                w.Write(tuning.GetMidiNote(arrangementType, 0, chordTemplate.Fret0));
                w.Write(tuning.GetMidiNote(arrangementType, 1, chordTemplate.Fret1));
                w.Write(tuning.GetMidiNote(arrangementType, 2, chordTemplate.Fret2));
                w.Write(tuning.GetMidiNote(arrangementType, 3, chordTemplate.Fret3));
                w.Write(tuning.GetMidiNote(arrangementType, 4, chordTemplate.Fret4));
                w.Write(tuning.GetMidiNote(arrangementType, 5, chordTemplate.Fret5));

                // chord name
                string name = chordTemplate.ChordName;
                if (name.Length > 32)
                {
                    name = name.Substring(0, 32);
                }
                foreach (char c in name)
                {
                    w.Write(Convert.ToByte(c));
                }
                // padding after name
                w.Write(new byte[32 - name.Length]);
            }
        }
        // COMPLETE
        private static void WriteRocksmithSngFile(Song rocksmithSong, InstrumentTuning tuning, ArrangementType arrangementType, string outputFile, EndianBitConverter bitConverter)
        {
            var iterationInfo = CreatePhraseIterationInfo(rocksmithSong);
            // WRITE THE .SNG FILE
            using (FileStream fs = new FileStream(outputFile, FileMode.Create))
            using (EndianBinaryWriter w = new EndianBinaryWriter(bitConverter, fs))
            {
                // HEADER
                WriteRocksmithSngHeader(w, arrangementType);

                // EBEATS DATA
                WriteRocksmithSngEbeats(w, rocksmithSong.Ebeats);

                // PHRASES
                WriteRocksmithSngPhrases(w, rocksmithSong.Phrases, rocksmithSong.PhraseIterations);

                // CHORD TEMPLATES
                WriteRocksmithSngChordTemplates(w, rocksmithSong.ChordTemplates, tuning, arrangementType);

                // FRET HAND MUTE TEMPLATE
                WriteRocksmithSngFretHandMuteTemplates(w, rocksmithSong.FretHandMuteTemplates);

                // VOCALS TEMPLATE
                w.Write(new byte[4]); // not used on song file

                // PHRASE ITERATIONS
                WriteRocksmithSngPhraseIterations(w, rocksmithSong.PhraseIterations, rocksmithSong.SongLength);

                // PHRASE PROPERTIES
                WriteRocksmithSngPhraseProperties(w, rocksmithSong.PhraseProperties);

                // LINKED DIFFS
                WriteRocksmithSngLinkedDiffs(w, rocksmithSong.LinkedDiffs);

                // CONTROLS
                WriteRocksmithSngControls(w, rocksmithSong.Controls);

                // EVENTS
                WriteRocksmithSngEvents(w, rocksmithSong.Events);

                // SECTIONS
                WriteRocksmithSngSections(w, rocksmithSong.Sections, rocksmithSong.PhraseIterations, rocksmithSong.SongLength);

                // LEVELS
                WriteRocksmithSngLevels(w, rocksmithSong.Levels, rocksmithSong.SongLength, iterationInfo, arrangementType);

                // SONG META DATA
                WriteRocksmithSngMetaDetails(w, rocksmithSong, tuning, iterationInfo);
            }
        }
        // COMPLETE
        private static void WriteRocksmithSngChordTemplates(EndianBinaryWriter w, SongChordTemplate[] chordTemplates, InstrumentTuning tuning, ArrangementType arrangementType)
        {
            // output header
            if (chordTemplates == null || chordTemplates.Length == 0)
            {
                w.Write(new byte[4]); // empty header
                return;
            }

            // output header count
            w.Write(chordTemplates.Length);

            // output chord templates
            foreach (SongChordTemplate chordTemplate in chordTemplates)
            {
                // fret numbers
                w.Write(chordTemplate.Fret0);
                w.Write(chordTemplate.Fret1);
                w.Write(chordTemplate.Fret2);
                w.Write(chordTemplate.Fret3);
                w.Write(chordTemplate.Fret4);
                w.Write(chordTemplate.Fret5);

                // finger positions
                w.Write(chordTemplate.Finger0);
                w.Write(chordTemplate.Finger1);
                w.Write(chordTemplate.Finger2);
                w.Write(chordTemplate.Finger3);
                w.Write(chordTemplate.Finger4);
                w.Write(chordTemplate.Finger5);

                // note values
                w.Write(tuning.GetMidiNote(arrangementType, 0, chordTemplate.Fret0));
                w.Write(tuning.GetMidiNote(arrangementType, 1, chordTemplate.Fret1));
                w.Write(tuning.GetMidiNote(arrangementType, 2, chordTemplate.Fret2));
                w.Write(tuning.GetMidiNote(arrangementType, 3, chordTemplate.Fret3));
                w.Write(tuning.GetMidiNote(arrangementType, 4, chordTemplate.Fret4));
                w.Write(tuning.GetMidiNote(arrangementType, 5, chordTemplate.Fret5));

                // chord name
                string name = chordTemplate.ChordName;
                if (name.Length > 32)
                {
                    name = name.Substring(0, 32);
                }
                foreach (char c in name)
                {
                    w.Write(Convert.ToByte(c));
                }
                // padding after name
                w.Write(new byte[32 - name.Length]);
            }
        }
        public static void Write(string inputFile, string outputFile, ArrangementType arrangementType, GamePlatform platform, InstrumentTuning tuning)
        {
            using (var reader = new StreamReader(inputFile))
            {
                var bitConverter = platform == GamePlatform.Pc
                    ? (EndianBitConverter)EndianBitConverter.Little
                    : (EndianBitConverter)EndianBitConverter.Big;

                if (arrangementType == ArrangementType.Vocal)
                {
                    var serializer = new XmlSerializer(typeof(Vocals));
                    var vocals = (Vocals)serializer.Deserialize(reader);
                    WriteRocksmithVocalsFile(vocals, outputFile, bitConverter);
                }
                else
                {
                    var serializer = new XmlSerializer(typeof(Song));
                    var song = (Song)serializer.Deserialize(reader);
                    WriteRocksmithSngFile(song, tuning, arrangementType, outputFile, bitConverter);
                }
            }
        }
        private void FillTuningCombo(ArrangementType arrangementType, GameVersion gameVersion)
        {
            tuningComboBox.Items.Clear();
            var tuningDefinitions = TuningDefinitionRepository.LoadTuningDefinitions(gameVersion);
            // LINQ method produces unexpected results on subsequent calls
            // foreach (var tuning in TuningDefinitionRepository.Instance().Select(gameVersion))
            foreach (var tuning in tuningDefinitions)
            {
                // need to populate for Vocals too even though not used
                //if (arrangementType != ArrangementType.Bass)
                tuningComboBox.Items.Add(tuning);
                //if (arrangementType == ArrangementType.Bass)
                // tuningComboBox.Items.Add(TuningDefinition.Convert2Bass(tuning));
            }

            tuningComboBox.SelectedIndex = 0;
            tuningComboBox.Refresh();
        }
        private void ShowTuningForm(ArrangementType selectedType, TuningDefinition tuning)
        {
            if (tuning == null)
            {
                MessageBox.Show("Pick a tuning definition to start editing.\r\n (Current tuning is Null)", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            bool addNew;
            TuningDefinition formTuning;
            using (var form = new TuningForm())
            {
                form.Tuning = tuning;
                form.IsBass = selectedType == ArrangementType.Bass;

                if (DialogResult.OK != form.ShowDialog())
                    return;

                // prevent any further SET calls to form.Tuning
                formTuning = form.Tuning;
                addNew = form.AddNew;
            }

            if (tuning.UIName != formTuning.UIName)
            {
                // Update LB slots if tuning name is changed
                for (int i = 0; i < parentControl.arrangementLB.Items.Count; i++)
                {
                    var selectedArrangement = (Arrangement)parentControl.arrangementLB.Items[i];

                    if (tuning.UIName.Equals(selectedArrangement.Tuning))
                    {
                        selectedArrangement.Tuning = formTuning.UIName;
                        parentControl.arrangementLB.Items[i] = selectedArrangement;
                    }
                }
            }

            // TODO: figure out logic behind unexpected LINQ behaviors
            // tuningComboBox list is being updated with custom tuning info
            // so refilling the combobox is required to produce the expected results
            // for now using old fashioned non-LINQ method
            FillTuningCombo(selectedType, currentGameVersion);

            int foundTuning = -1;
            tuningComboBox.SelectedIndex = -1;
            for (int tcbIndex = 0; tcbIndex < tuningComboBox.Items.Count; tcbIndex++)
            {
                tuningComboBox.SelectedIndex = tcbIndex;
                tuning = (TuningDefinition)tuningComboBox.Items[tcbIndex];
                if (tuning.Tuning == formTuning.Tuning)
                {
                    foundTuning = tcbIndex;
                    break;
                }
            }

            // add the custom tuning to tuningComboBox
            if (foundTuning == -1)
            {
                formTuning.Custom = true;
                tuningComboBox.Items.Add(formTuning);
                tuningComboBox.SelectedIndex = tuningComboBox.Items.Count - 1;

                if (addNew)
                    SaveTuningDefinition(formTuning);
            }
            else
                tuningComboBox.SelectedIndex = foundTuning;

            tuningComboBox.Refresh();
            Arrangement.TuningStrings = formTuning.Tuning; // forces SET update
        }
Beispiel #40
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 #41
0
        private void ShowTuningForm(ArrangementType selectedType, TuningDefinition tuning)
        {
            if (tuning == null)
            {
                MessageBox.Show("Pick a tuning definition to start editing.\r\n (Current tuning is Null)", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            bool             addNew;
            TuningDefinition formTuning;

            using (var form = new TuningForm())
            {
                form.Tuning = tuning;
                form.IsBass = selectedType == ArrangementType.Bass;

                if (DialogResult.OK != form.ShowDialog())
                {
                    return;
                }

                // prevent any further SET calls to form.Tuning
                formTuning = form.Tuning;
                addNew     = form.AddNew;
            }

            if (tuning.UIName != formTuning.UIName)
            {
                // Update LB slots if tuning name is changed
                for (int i = 0; i < parentControl.arrangementLB.Items.Count; i++)
                {
                    var selectedArrangement = (Arrangement)parentControl.arrangementLB.Items[i];

                    if (tuning.UIName.Equals(selectedArrangement.Tuning))
                    {
                        selectedArrangement.Tuning           = formTuning.UIName;
                        parentControl.arrangementLB.Items[i] = selectedArrangement;
                    }
                }
            }

            // TODO: figure out logic behind unexpected LINQ behaviors
            // tuningComboBox list is being updated with custom tuning info
            // so refilling the combobox is required to produce the expected results
            // for now using old fashioned non-LINQ method
            FillTuningCombo(selectedType, currentGameVersion);

            int foundTuning = -1;

            tuningComboBox.SelectedIndex = -1;
            for (int tcbIndex = 0; tcbIndex < tuningComboBox.Items.Count; tcbIndex++)
            {
                tuningComboBox.SelectedIndex = tcbIndex;
                tuning = (TuningDefinition)tuningComboBox.Items[tcbIndex];
                if (tuning.Tuning == formTuning.Tuning)
                {
                    foundTuning = tcbIndex;
                    break;
                }
            }

            // add the custom tuning to tuningComboBox
            if (foundTuning == -1)
            {
                formTuning.Custom = true;
                tuningComboBox.Items.Add(formTuning);
                tuningComboBox.SelectedIndex = tuningComboBox.Items.Count - 1;

                if (addNew)
                {
                    SaveTuningDefinition(formTuning);
                }
            }
            else
            {
                tuningComboBox.SelectedIndex = foundTuning;
            }

            tuningComboBox.Refresh();
            Arrangement.TuningStrings = formTuning.Tuning; // forces SET update
        }
        // COMPLETE
        private static void WriteSngFile(Song rocksmithSong, InstrumentTuning tuning, ArrangementType arrangementType, string outputFile, EndianBitConverter bitConverter)
        {
            var iterationInfo = CreatePhraseIterationInfo(rocksmithSong);

            // WRITE THE .SNG FILE
            using (FileStream fs = new FileStream(outputFile, FileMode.Create))
                using (EndianBinaryWriter w = new EndianBinaryWriter(bitConverter, fs))
                {
                    // HEADER
                    WriteRocksmithSngHeader(w, arrangementType);

                    // EBEATS DATA
                    WriteRocksmithSngEbeats(w, rocksmithSong.Ebeats);

                    // PHRASES
                    WriteRocksmithSngPhrases(w, rocksmithSong.Phrases, rocksmithSong.PhraseIterations);

                    // CHORD TEMPLATES
                    WriteRocksmithSngChordTemplates(w, rocksmithSong.ChordTemplates, tuning, arrangementType);

                    // FRET HAND MUTE TEMPLATE
                    WriteRocksmithSngFretHandMuteTemplates(w, rocksmithSong.FretHandMuteTemplates);

                    // VOCALS TEMPLATE
                    w.Write(new byte[4]); // not used on song file

                    // PHRASE ITERATIONS
                    WriteRocksmithSngPhraseIterations(w, rocksmithSong.PhraseIterations, rocksmithSong.SongLength);

                    // PHRASE PROPERTIES
                    WriteRocksmithSngPhraseProperties(w, rocksmithSong.PhraseProperties);

                    // LINKED DIFFS
                    WriteRocksmithSngLinkedDiffs(w, rocksmithSong.LinkedDiffs);

                    // CONTROLS
                    WriteRocksmithSngControls(w, rocksmithSong.Controls);

                    // EVENTS
                    WriteRocksmithSngEvents(w, rocksmithSong.Events);

                    // SECTIONS
                    WriteRocksmithSngSections(w, rocksmithSong.Sections, rocksmithSong.PhraseIterations, rocksmithSong.SongLength);

                    // LEVELS
                    WriteRocksmithSngLevels(w, rocksmithSong.Levels, rocksmithSong.SongLength, iterationInfo, arrangementType);

                    // SONG META DATA
                    WriteRocksmithSngMetaDetails(w, rocksmithSong, tuning, iterationInfo);
                }
        }
 // COMPLETE
 private static void WriteRocksmithSngHeader(EndianBinaryWriter w, ArrangementType arrangementType)
 {
     w.Write(arrangementType == ArrangementType.Bass ? 51 : 49); // version num?
 }
 // COMPLETE
 private static void WriteRocksmithSngHeader(EndianBinaryWriter w, ArrangementType arrangementType)
 {
     w.Write(arrangementType == ArrangementType.Bass ? 51 : 49); // version num?
 }
        // COMPLETE except hardcoded fields
        private static void WriteRocksmithSngLevelNotes(EndianBinaryWriter w, List<PhraseIterationInfo> iterationInfo, SongNote[] notes, SongChord[] chords, Single songLength, ArrangementType arrangementType)
        {
            List<TimeLinkedEntity> notesChords = new List<TimeLinkedEntity>();

            // add notes to combined note/chord array
            if (notes != null && notes.Length != 0)
            {
                notesChords.AddRange(notes.Select(note =>
                    new TimeLinkedEntity
                    {
                        Time = note.Time,
                        Entity = note
                    }));
            }

            // add chords to combined note/chord array
            if (chords != null && chords.Length != 0)
            {
                notesChords.AddRange(chords.Select(chord =>
                    new TimeLinkedEntity
                    {
                        Time = chord.Time,
                        Entity = chord
                    }));
            }

            // sort the notes and chords by time
            notesChords.Sort((s1, s2) => s1.Time.CompareTo(s2.Time));

            // write empty header if no notes or chords
            if (notesChords.Count == 0)
            {
                w.Write(new byte[4]); // empty header
                return;
            }

            // output notes and chords header count
            w.Write(notesChords.Count);

            // ouput notes and chords
            for (int i = 0; i < (notesChords.Count); i++)
            {
                // note time tag
                w.Write(notesChords[i].Time);

                // string tag
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).String : -1);

                // fret tag
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Fret : -1);

                // chord id
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? -1 : ((SongChord)notesChords[i].Entity).ChordId);

                // unknown
                w.Write(Convert.ToInt32(-1));

                // sustain time
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Sustain : 0);

                // bend
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Bend : 0);

                // slideTo
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).SlideTo : -1);

                // tremolo
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Tremolo : new byte());

                // harmonic
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Harmonic : new byte());

                // palm mute
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).PalmMute : new byte());

                if (arrangementType == ArrangementType.Bass)
                {
                    w.Write(new byte());//unknownB

                    //Bass only - Slap
                    w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Slap : -1);

                    //Bass only - Pluck
                    w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Pluck : -1);
                }

                // hopo
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Hopo : new byte());

                // hammerOn
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).HammerOn : new byte());

                // pullOff
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).PullOff : new byte());

                // ignore
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Ignore : ((SongChord)notesChords[i].Entity).Ignore);

                // high density chord
                if (arrangementType == ArrangementType.Bass)
                {
                    w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? new byte() : ((SongChord)notesChords[i].Entity).HighDensity);
                    w.Write(new byte());
                    w.Write((byte)140);
                    w.Write(new byte());
                }
                else
                {
                    w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? new byte() : ((SongChord)notesChords[i].Entity).HighDensity);
                    w.Write(new byte[4]);
                }

                //w.Write(Convert.ToInt16(246));
                //w.Write(Convert.ToInt16(7472));

                // phrase iteration start index and id ????
                bool phraseStartIterationFound = false;
                foreach (var iteration in iterationInfo)
                {
                    if (notesChords[i].Time >= iteration.StartTime && notesChords[i].Time < iteration.EndTime)
                    {
                        w.Write(iteration.IterationId); // phrase iteration
                        w.Write(iteration.PhraseId);
                        phraseStartIterationFound = true;
                        break;
                    }
                }
                if (!phraseStartIterationFound)
                {
                    throw new Exception(string.Format("No phrase start iteration found with matching time for note {0}.", i.ToString()));
                }
            }
        }
        // INCOMPLETE
        // section begins at @ 9,820 in NumberThirteen_Lead.sng
        private static void WriteRocksmithSngLevels(EndianBinaryWriter w, Xml.SongLevel[] levels, Single songLength, List<PhraseIterationInfo> iterationInfo, ArrangementType arrangementType)
        {
            // output header
            if (levels == null || levels.Length == 0)
            {
                w.Write(new byte[4]); // empty header
                return;
            }

            // output header count
            w.Write(levels.Length);

            // output
            foreach (var level in levels)
            {
                // level difficulty tag
                w.Write(level.Difficulty);

                // anchors
                WriteRocksmithSngLevelAnchors(w, level.Anchors, level, iterationInfo, songLength);

                // slide properties
                WriteRockmithSngLevelSlideProperties(w, level.Notes);

                // handshapes
                WriteRocksmithSngLevelHandShapes(w, level.HandShapes, level, songLength);

                // notes and chords
                WriteRocksmithSngLevelNotes(w, iterationInfo, level.Notes, level.Chords, songLength, arrangementType);

                var iterationNotes = new List<int>();
                foreach (var iteration in iterationInfo)
                {
                    int num = 0;
                    if (level.Notes != null)
                    {
                        num += level.Notes.Where(n => n.Time >= iteration.StartTime && n.Time < iteration.EndTime).Count();
                    }
                    if (level.Chords != null)
                    {
                        num += level.Chords.Where(n => n.Time >= iteration.StartTime && n.Time < iteration.EndTime).Count();
                    }
                    iterationNotes.Add(num);
                }

                var phrases = iterationInfo.GroupBy(it => it.PhraseId).OrderBy(grp => grp.Key); ;
                // count of phrases
                w.Write(phrases.Count());
                foreach (var phrase in phrases)
                {
                    float notes = (float)phrase.Sum(iteration => iterationNotes[iteration.IterationId]);
                    float count = phrase.Count();

                    w.Write(notes / count); // This is the number of notes + chords in all iterations of this phrase for this level, divided by number of iterations of this phrase
                }

                // count of phrase iterations
                w.Write(iterationInfo.Count);
                foreach (var iterationNoteCount in iterationNotes)
                {
                    w.Write(iterationNoteCount);// This appears to be the number of notes + chords in each iteration for this level
                }

                // count of phrase iterations
                w.Write(iterationInfo.Count);
                foreach (var iterationNoteCount in iterationNotes)
                {
                    w.Write(iterationNoteCount);// This appears to be the number of notes + chords in each iteration for this level
                }
            }
        }
        // COMPLETE except hardcoded fields
        private static void WriteRocksmithSngLevelNotes(EndianBinaryWriter w, List <PhraseIterationInfo> iterationInfo, SongNote[] notes, SongChord[] chords, Single songLength, ArrangementType arrangementType)
        {
            List <TimeLinkedEntity> notesChords = new List <TimeLinkedEntity>();

            // add notes to combined note/chord array
            if (notes != null && notes.Length != 0)
            {
                notesChords.AddRange(notes.Select(note =>
                                                  new TimeLinkedEntity
                {
                    Time   = note.Time,
                    Entity = note
                }));
            }

            // add chords to combined note/chord array
            if (chords != null && chords.Length != 0)
            {
                notesChords.AddRange(chords.Select(chord =>
                                                   new TimeLinkedEntity
                {
                    Time   = chord.Time,
                    Entity = chord
                }));
            }

            // sort the notes and chords by time
            notesChords.Sort((s1, s2) => s1.Time.CompareTo(s2.Time));

            // write empty header if no notes or chords
            if (notesChords.Count == 0)
            {
                w.Write(new byte[4]); // empty header
                return;
            }

            // output notes and chords header count
            w.Write(notesChords.Count);

            // ouput notes and chords
            for (int i = 0; i < (notesChords.Count); i++)
            {
                // note time tag
                w.Write(notesChords[i].Time);

                // string tag
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).String : -1);

                // fret tag
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Fret : (sbyte)-1);

                // chord id
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? -1 : ((SongChord)notesChords[i].Entity).ChordId);

                // unknown
                w.Write(Convert.ToInt32(-1));

                // sustain time
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Sustain : 0);

                // bend
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Bend : (byte)0);

                // slideTo
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).SlideTo : (sbyte)-1);

                // tremolo
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Tremolo : new byte());

                // harmonic
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Harmonic : new byte());

                // palm mute
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).PalmMute : new byte());

                if (arrangementType == ArrangementType.Bass)
                {
                    w.Write(new byte());//unknownB

                    //Bass only - Slap
                    w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Slap : (sbyte)-1);

                    //Bass only - Pluck
                    w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Pluck : (sbyte)-1);
                }

                // hopo
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Hopo : new byte());

                // hammerOn
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).HammerOn : new byte());

                // pullOff
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).PullOff : new byte());

                // ignore
                w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? ((SongNote)notesChords[i].Entity).Ignore : ((SongChord)notesChords[i].Entity).Ignore);

                // high density chord
                if (arrangementType == ArrangementType.Bass)
                {
                    w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? new byte() : (byte)((SongChord)notesChords[i].Entity).HighDensity);
                    w.Write(new byte());
                    w.Write((byte)140);
                    w.Write(new byte());
                }
                else
                {
                    w.Write(notesChords[i].Entity.GetType() == typeof(SongNote) ? new byte() : ((SongChord)notesChords[i].Entity).HighDensity);
                    w.Write(new byte[4]);
                }

                //w.Write(Convert.ToInt16(246));
                //w.Write(Convert.ToInt16(7472));

                // phrase iteration start index and id ????
                bool phraseStartIterationFound = false;
                foreach (var iteration in iterationInfo)
                {
                    if (notesChords[i].Time >= iteration.StartTime && notesChords[i].Time < iteration.EndTime)
                    {
                        w.Write(iteration.IterationId); // phrase iteration
                        w.Write(iteration.PhraseId);
                        phraseStartIterationFound = true;
                        break;
                    }
                }
                if (!phraseStartIterationFound)
                {
                    throw new Exception(string.Format("No phrase start iteration found with matching time for note {0}.", i.ToString()));
                }
            }
        }
Beispiel #48
0
        private void ShowTuningForm(ArrangementType selectedType, TuningDefinition tuning)
        {
            if (tuning == null)
            {
                MessageBox.Show("Pick a tuning definition to start editing.\r\n (DEBUG: Current tuning is Null)", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // get the latest comments from the XML to check if previous bass fixed is valid
            if (!String.IsNullOrEmpty(Arrangement.SongXml.File) && selectedType == ArrangementType.Bass)
            {
                //var debugMe = "";
                var xmlComments = Song2014.ReadXmlComments(Arrangement.SongXml.File);
                var isBassFixed = xmlComments.Any(xComment => xComment.ToString().Contains("Low Bass Tuning Fixed")) || Convert.ToDouble(txtFrequency.Text) == 220.00;

                // commented out ... Arrangement.XmlComments may not be populated
                // var isBassFixed = Arrangement.XmlComments.Any(xComment => xComment.ToString().Contains("Low Bass Tuning Fixed")) || Convert.ToDouble(txtFrequency.Text) == 220.00;

                if (isBassFixed && !tuning.UIName.Contains("Fixed"))
                {
                    // UIName may contain spaces, where as Name contains no spaces
                    tuning.UIName = String.Format("{0} Fixed", tuning.UIName);
                    tuning.Name = tuning.UIName.ReplaceSpaceWith("");
                    tuning.Custom = true;
                    // fixed bass tuning definition is auto added to repository
                    TuningDefinitionRepository.SaveUnique(tuning);
                }
            }

            bool addNew;
            TuningDefinition formTuning;
            using (var form = new TuningForm())
            {
                form.Tuning = tuning;
                form.IsBass = selectedType == ArrangementType.Bass;

                if (DialogResult.OK != form.ShowDialog())
                    return;

                // prevent any further SET calls to form.Tuning
                formTuning = form.Tuning;
                addNew = form.AddNew;
            }

            if (tuning.UIName != formTuning.UIName)
            {
                // Update lstArrangements slots if tuning name is changed
                for (int i = 0; i < _parentControl.lstArrangements.Items.Count; i++)
                {
                    var selectedArrangement = (Arrangement)_parentControl.lstArrangements.Items[i];

                    if (tuning.UIName.Equals(selectedArrangement.Tuning))
                    {
                        selectedArrangement.Tuning = formTuning.UIName;
                        _parentControl.lstArrangements.Items[i] = selectedArrangement;
                    }
                }
            }

            FillTuningCombo(_gameVersion);

            int foundTuning = -1;
            cmbTuningName.SelectedIndex = -1;
            for (int tcbIndex = 0; tcbIndex < cmbTuningName.Items.Count; tcbIndex++)
            {
                cmbTuningName.SelectedIndex = tcbIndex;
                tuning = (TuningDefinition)cmbTuningName.Items[tcbIndex];

                // check at least tuning strings and name match
                if (tuning.Tuning == formTuning.Tuning && tuning.Name == formTuning.Name)
                {
                    foundTuning = tcbIndex;
                    break;
                }
            }

            // add the custom tuning to tuningComboBox
            if (foundTuning == -1)
            {
                if (addNew)
                    TuningDefinitionRepository.SaveUnique(formTuning);

                formTuning.Custom = true;
                cmbTuningName.Items.Add(formTuning);
                cmbTuningName.SelectedIndex = cmbTuningName.Items.Count - 1;
            }
            else
                cmbTuningName.SelectedIndex = foundTuning;

            cmbTuningName.Refresh();
            Arrangement.TuningStrings = formTuning.Tuning;
            Arrangement.Tuning = formTuning.UIName;
        }