public void GenerateChords(Attributes2014 attribute, Song2014 song)
        {
            // Some ODLC contain JSON Chords errors, this method is producing workable results
            //
            // USING song.Levels[difficulty].HandShapes METHOD
            // the handshape data can be used to obtain chordIds
            // (more efficient less data to iterate through)
            //
            //"Chords" : {
            //     "DiffLevelID" : {//used to display which chord is set at current lvl.
            //         "SectionID" : [// >= 0
            //             ChordID,
            //             ChordID
            //         ]
            //     },
            // }

            if (song.Sections == null)
            {
                return;
            }

            attribute.Chords = new Dictionary <string, Dictionary <string, List <int> > >();
            for (int difficulty = 0; difficulty < song.Levels.Length; difficulty++)
            {
                var chords    = song.Levels[difficulty].HandShapes;
                var sectionId = new Dictionary <string, List <int> >();
                var chordId   = new List <int>();

                for (int section = 0; section < song.Sections.Length; section++)
                {
                    var sectionNumber = song.Sections[section].Number;
                    var starTime      = song.Sections[section].StartTime;
                    var endTime       = song.Sections[Math.Min(section + 1, song.Sections.Length - 1)].StartTime;

                    // iterate through chords in handshapes in the difficulty level
                    foreach (var chord in chords)
                    {
                        if (chord.StartTime >= starTime && chord.EndTime < endTime) //in range
                        {
                            chordId.Add(chord.ChordId);
                        }
                    }

                    if (chordId.Count > 0)
                    {
                        // always ordered in ODLC
                        List <int> distinctChordIds = chordId.Distinct().OrderBy(x => x).ToList();
                        sectionId.Add(section.ToString(), distinctChordIds);
                    }

                    chordId = new List <int>();
                }

                if (sectionId.Keys.Count > 0)
                {
                    attribute.Chords.Add(difficulty.ToString(), sectionId);
                }
            }
        }
        /// <summary>
        /// Set Arrangement Type and Tuning information.
        /// </summary>
        /// <param name="song"></param>
        private void DetectTuning(Song2014 song)
        {
            var t = TuningDefinitionRepository.Instance.Detect(song.Tuning, GameVersion.RS2014, ArrangementType == ArrangementType.Guitar);

            Tuning        = t.UIName;
            TuningStrings = t.Tuning;
        }
Esempio n. 3
0
        private bool FixBassTuning()
        {
            // fix old toolkit behavior
            if (Arrangement.TuningStrings == null)
            {
                Arrangement.TuningStrings = new TuningStrings { String0 = 0, String1 = 0, String2 = 0, String3 = 0, String4 = 0, String5 = 0 };
                return false;
            }

            if (_gameVersion == GameVersion.RS2012)
                return false;

            var bassFix = false;
            //Low tuning fix for bass, If lowest string is B and bass fix not applied 
            if (Arrangement.TuningStrings.String0 < -4 && Arrangement.TuningPitch != 220.00)
                if (_fixLowBass)
                    bassFix = true;
                else
                    bassFix |= MessageBox.Show(@"The bass tuning may be too low.  Apply Low Bass Tuning Fix?" + Environment.NewLine + @"Note: The fix may revert if bass Arrangement is re-saved in EOF.  ", @"Warning ... Low Bass Tuning", MessageBoxButtons.YesNo) == DialogResult.Yes;

            // Fix Low Bass Tuning
            if (bassFix && TuningFrequency.ApplyBassFix(Arrangement, _fixLowBass))
            {
                Arrangement.TuningStrings = Song2014.LoadFromFile(Arrangement.SongXml.File).Tuning;
                Arrangement.TuningPitch = 220.00;
                txtFrequency.Text = "220.00";

                return true;
            }

            return false;
        }
Esempio n. 4
0
        static Dictionary <int, ChordTemplate> GetChordTemplates(Song2014 arrangement)
        {
            var templates = new Dictionary <int, ChordTemplate>();

            for (int i = 0; i < arrangement.ChordTemplates.Length; ++i)
            {
                var rsTemplate = arrangement.ChordTemplates[i];

                var template = new ChordTemplate()
                {
                    ChordId = i,
                    Name    = rsTemplate.ChordName,
                    Frets   = new int[] { rsTemplate.Fret0, rsTemplate.Fret1, rsTemplate.Fret2,
                                          rsTemplate.Fret3, rsTemplate.Fret4, rsTemplate.Fret5 },
                    Fingers = new int[] { rsTemplate.Finger0, rsTemplate.Finger1,
                                          rsTemplate.Finger2, rsTemplate.Finger3, rsTemplate.Finger4,
                                          rsTemplate.Finger5 }
                };
                // correct for capo position. this is necessary since Rocksmith is weird when using
                // a capo: the open string is indexed as 0, but any pressed fret is given as the
                // absolute fret, not relative to the capo.
                for (int j = 0; j < 6; ++j)
                {
                    if (template.Frets[j] > 0)
                    {
                        template.Frets[j] -= arrangement.Capo;
                    }
                }

                templates.Add(template.ChordId, template);
            }

            return(templates);
        }
Esempio n. 5
0
        static void AddSectionNames(Song2014 arrangement, List <Bar> bars)
        {
            var sections = arrangement.Sections.OrderBy(x => x.StartTime);
            int c        = 0;
            int b        = 0;

            foreach (var section in sections)
            {
                while (b < bars.Count && bars[b].Chords[c].Start < section.StartTime)
                {
                    ++c;
                    if (c >= bars[b].Chords.Count)
                    {
                        c = 0;
                        ++b;
                    }
                }

                if (b < bars.Count)
                {
                    var chord = bars[b].Chords[c];
                    chord.Section = section.Name.ToUpper();
                }
            }
        }
Esempio n. 6
0
        /// <param name="song"></param>
        /// <param name="difficultyLevel">null = highest level available</param>
        public static Score GetScoreForExactDifficultyLevel(Song2014 song, int?difficultyLevel)
        {
            SongLevel2014 selectedLevel;

            if (difficultyLevel.HasValue)
            {
                selectedLevel = song.Levels.FirstOrDefault(x => x.Difficulty == difficultyLevel);
            }
            else
            {
                selectedLevel = song.Levels.OrderBy(x => x.Difficulty).LastOrDefault();
            }

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

            var allSounds = selectedLevel.Notes.Select(x => new SongNoteChordWrapper(x))
                            .Union(selectedLevel.Chords.Select(x => new SongNoteChordWrapper(x)));

            var score = CreateSong(song, allSounds);

            return(score);
        }
Esempio n. 7
0
        /// <param name="song"></param>
        /// <param name="difficultyLevel">null = highest level available</param>
        public static Score GetScoreForMaxDifficultyLevel(Song2014 song, int?difficultyLevel)
        {
            List <PhraseIterationWithEndTime> iterationsWithEndTime = PhraseIterationWithEndTime.listFromBaseArray(song.PhraseIterations);

            IEnumerable <SongNoteChordWrapper> allSounds = Enumerable.Empty <SongNoteChordWrapper>();

            for (int phraseId = 0; phraseId < song.Phrases.Length; phraseId++)
            {
                var phrase    = song.Phrases[phraseId];
                var diffLevel = phrase.MaxDifficulty;
                if (difficultyLevel.HasValue && difficultyLevel < diffLevel)
                {
                    diffLevel = difficultyLevel.Value;
                }

                var selectedLevel = song.Levels.FirstOrDefault(x => x.Difficulty == diffLevel);

                var phraseIterations = iterationsWithEndTime.Where(x => x.PhraseId == phraseId).ToArray();
                for (int i = 0; i < phraseIterations.Length; i++)
                {
                    var iterationWithEndTime = phraseIterations[i];
                    var notes  = selectedLevel.Notes.Where(x => iterationWithEndTime.contains(x.Time));
                    var chords = selectedLevel.Chords.Where(x => iterationWithEndTime.contains(x.Time));

                    allSounds = allSounds.Union(notes.Select(x => new SongNoteChordWrapper(x)))
                                .Union(chords.Select(x => new SongNoteChordWrapper(x)));
                }
            }
            var score = CreateSong(song, allSounds);

            return(score);
        }
Esempio n. 8
0
        static void ExportArrangement(Score score, Song2014 arrangement, string identifier, int difficulty,
                                      string originalFile, ToolkitInfo toolkitInfo)
        {
            var track = Converter.ConvertArrangement(arrangement, identifier, difficulty);

            score.Tracks.Add(track);
            score.Title      = arrangement.Title;
            score.Artist     = arrangement.ArtistName;
            score.ArtistSort = arrangement.ArtistNameSort;
            score.Album      = arrangement.AlbumName;
            score.Year       = arrangement.AlbumYear;
            score.Comments   = new List <string>();
            score.Comments.Add("Generated by RocksmithToTab v" + VersionInfo.VERSION);
            score.Comments.Add("=> http://www.rocksmithtotab.de");
            score.Comments.Add("Created from archive: " + Path.GetFileName(originalFile));
            if (toolkitInfo != null && toolkitInfo.PackageAuthor != string.Empty)
            {
                score.Comments.Add("CDLC author:  " + toolkitInfo.PackageAuthor);
                score.Tabber = toolkitInfo.PackageAuthor;
            }
            if (toolkitInfo != null && toolkitInfo.PackageVersion != string.Empty)
            {
                score.Comments.Add("CDLC version: " + toolkitInfo.PackageVersion);
            }
        }
Esempio n. 9
0
        public static void UpdateXml(Arrangement arr, DLCPackageData info)
        {
            // update xml with user modified DLCPackageData info
            var songXml = Song2014.LoadFromFile(arr.SongXml.File);

            arr.SongFile = new RocksmithToolkitLib.DLCPackage.AggregateGraph.SongFile {
                File = ""
            };
            arr.Id       = IdGenerator.Guid();
            arr.MasterId = RandomGenerator.NextInt();

            songXml.AlbumName      = info.SongInfo.Album;
            songXml.AlbumYear      = info.SongInfo.SongYear.ToString();
            songXml.ArtistName     = info.SongInfo.Artist;
            songXml.ArtistNameSort = info.SongInfo.ArtistSort;
            songXml.AverageTempo   = info.SongInfo.AverageTempo;
            songXml.Title          = info.SongInfo.SongDisplayName;
            songXml.ToneBase       = arr.ToneBase;
            songXml.ToneA          = arr.ToneA;
            songXml.ToneB          = arr.ToneB;
            songXml.ToneC          = arr.ToneC;
            songXml.ToneD          = arr.ToneD;

            File.Delete(arr.SongXml.File);
            using (var stream = File.OpenWrite(arr.SongXml.File))
            {
                songXml.Serialize(stream);
            }
        }
Esempio n. 10
0
        public TrackDetail GetTrackDetail(string songKey, string arrangmentName)
        {
            var sngEntry  = _psarc.Entries.FirstOrDefault(x => x.Name == @"songs/bin/generic/" + songKey + "_" + arrangmentName + ".sng");
            var jsonEntry = _psarc.Entries.FirstOrDefault(x => x.Name.StartsWith(@"manifests/songs") && x.Name.EndsWith("/" + songKey + "_" + arrangmentName + ".json"));

            if (sngEntry == null || jsonEntry == null)
            {
                return(null);
            }

            Attributes2014 att;

            using (var wrappedStream = new NonClosingStreamWrapper(jsonEntry.Data))
            {
                using (var reader = new StreamReader(wrappedStream))
                {
                    var manifest = JsonConvert.DeserializeObject <Manifest2014 <Attributes2014> >(reader.ReadToEnd());
                    att = manifest.Entries.ToArray()[0].Value.ToArray()[0].Value;
                }
            }

            Sng2014File sngFile;

            using (var wrappedStream = new NonClosingStreamWrapper(sngEntry.Data))
            {
                var platform = _archiveFile.GetPlatform();
                sngFile = Sng2014File.ReadSng(wrappedStream, platform);
            }
            var sngObject = new Song2014(sngFile, att);

            return(new TrackDetail()
            {
                RockSmithSong = sngObject
            });
        }
        private Song2014 ConvertChordTemplates(Song rsSong, Song2014 rsSong2014)
        {
            // add chordTemplates elements
            var chordTemplate = new List <SongChordTemplate2014>();

            foreach (var songChordTemplate in rsSong.ChordTemplates)
            {
                // tested ... not the source of game hangs
                //if (String.IsNullOrEmpty(songChordTemplate.ChordName))
                //    continue;

                chordTemplate.Add(new SongChordTemplate2014 {
                    ChordName = songChordTemplate.ChordName, DisplayName = songChordTemplate.ChordName, Finger0 = (sbyte)songChordTemplate.Finger0, Finger1 = (sbyte)songChordTemplate.Finger1, Finger2 = (sbyte)songChordTemplate.Finger2, Finger3 = (sbyte)songChordTemplate.Finger3, Finger4 = (sbyte)songChordTemplate.Finger4, Finger5 = (sbyte)songChordTemplate.Finger5, Fret0 = (sbyte)songChordTemplate.Fret0, Fret1 = (sbyte)songChordTemplate.Fret1, Fret2 = (sbyte)songChordTemplate.Fret2, Fret3 = (sbyte)songChordTemplate.Fret3, Fret4 = (sbyte)songChordTemplate.Fret4, Fret5 = (sbyte)songChordTemplate.Fret5
                });
            }

            // tested ... not the source of game hangs
            // get rid of duplicate chords if any
            // chordTemplate = chordTemplate.Distinct().ToList();

            // tested ... could be source of game hangs
            if (rsSong.ChordTemplates == null)
            {
                Console.WriteLine("Applied fix to RS1->RS2 ChordTemplates conversion");
                rsSong2014.ChordTemplates = new SongChordTemplate2014[0];
            }
            else
            {
                rsSong2014.ChordTemplates = chordTemplate.ToArray();
            }

            return(rsSong2014);
        }
        private static void AddSongMetadata(Song2014 rsSong, ZpeSong zigSong, string arrangment)
        {
            // standard meta header data
            rsSong.Version                = "7";
            rsSong.Arrangement            = arrangment;
            rsSong.Part                   = 1;
            rsSong.Offset                 = 0;
            rsSong.CentOffset             = "0";
            rsSong.StartBeat              = 0;
            rsSong.Capo                   = 0;
            rsSong.AlbumName              = "Unknown Album";
            rsSong.AlbumYear              = DateTime.Now.ToString("yyyy");
            rsSong.CrowdSpeed             = "1";
            rsSong.LastConversionDateTime = DateTime.Now.ToString();
            rsSong.SongLength             = zigSong.Length;

            Regex regex = new Regex(" - ");

            string[] artistTitle = regex.Split(zigSong.Name);
            rsSong.ArtistName = artistTitle[0] == null ? zigSong.Name : artistTitle[0];
            rsSong.Title      = artistTitle[1] == null ? zigSong.Name : artistTitle[1];

            ZpeTempo tempo = zigSong.Tracks[0].Tempos[0];
            float    BPM   = (float)Math.Round((float)60000000 / tempo.RawTempo, 3);

            rsSong.AverageTempo = BPM;

            ZpeTuning tuning = null;

            for (int i = 0; i < zigSong.Tunings.Tuning.Count; i++)
            {
                if (arrangment == "Lead" || arrangment == "Rhythm")
                {
                    if (zigSong.Tunings.Tuning[i].IsGuitarTuning)
                    {
                        tuning = zigSong.Tunings.Tuning[i];
                        break;
                    }
                }

                if (arrangment == "Bass")
                {
                    if (zigSong.Tunings.Tuning[i].IsBassTuning)
                    {
                        tuning = zigSong.Tunings.Tuning[i];
                        break;
                    }
                }
            }

            if (tuning == null)
            {
                throw new Exception("ZPE XML does not contain tuning");
            }

            rsSong.Tuning = new TuningStrings {
                String0 = tuning.E, String1 = tuning.A, String2 = tuning.D, String3 = tuning.G, String4 = tuning.B, String5 = tuning.HighE
            };
        }
Esempio n. 13
0
        /// <summary>
        /// Load a XML arrangment into memory and
        /// convert to GuitarPro file
        /// </summary>
        /// <param name="inputFilePath"></param>
        /// <param name="outputDir"></param>
        /// <param name="outputFormat"></param>
        /// <param name="allDif"></param>
        public void XmlToGp5(string inputFilePath, string outputDir, string outputFormat = "gp5", bool allDif = false)
        {
            Console.WriteLine("Opening arrangement {0} ...", inputFilePath);
            Console.WriteLine();
            var score       = new Score();
            var arrangement = Song2014.LoadFromFile(inputFilePath);
            var toolkitInfo = new ToolkitInfo();

            toolkitInfo.ToolkitVersion = String.Format("CST v{0}", ToolkitVersion.version);
            toolkitInfo.PackageAuthor  = "XML To GP5 Converter";
            toolkitInfo.PackageVersion = arrangement.LastConversionDateTime;

            var comments = Song2014.ReadXmlComments(inputFilePath);

            foreach (var xComment in comments)
            {
                if (xComment.Value.Contains("CST"))
                {
                    toolkitInfo.ToolkitVersion = xComment.Value.Trim();
                    break;
                }
            }

            // get maximum difficulty for the arrangement
            var mf     = new ManifestFunctions(GameVersion.RS2014);
            int maxDif = mf.GetMaxDifficulty(arrangement);

            if (allDif) // create separate file for each difficulty
            {
                for (int difLevel = 0; difLevel <= maxDif; difLevel++)
                {
                    ExportArrangement(score, arrangement, difLevel, inputFilePath, toolkitInfo);
                    Console.WriteLine("Difficulty Level: {0}", difLevel);

                    var baseFileName = CleanFileName(
                        String.Format("{0} - {1}", score.Artist, score.Title));
                    baseFileName += String.Format(" ({0})", arrangement.Arrangement);
                    baseFileName += String.Format(" (level {0:D2})", difLevel);

                    SaveScore(score, baseFileName, outputDir, outputFormat);
                    // remember to remove the track from the score again
                    score.Tracks.Clear();
                }
            }
            else // combine maximum difficulty arrangements into one file
            {
                Console.WriteLine("Maximum Difficulty Level: {0}", maxDif);
                ExportArrangement(score, arrangement, maxDif, inputFilePath, toolkitInfo);
            }

            if (!allDif) // only maximum difficulty
            {
                var baseFileName = CleanFileName(
                    String.Format("{0} - {1}", score.Artist, score.Title));
                SaveScore(score, baseFileName, outputDir, outputFormat);
            }
        }
Esempio n. 14
0
        public Showlights Genegate(string xmlFile)
        {
            var midiNotes  = new List <Showlight>();
            var chordNotes = new List <Showlight>();
            var ShowL      = new Showlights();
            var song       = Song2014.LoadFromFile(xmlFile);

            // If vocals
            if (song.Phrases == null || song.Tuning == null)
            {
                return(null);
            }
            //Generate ShowlightList
            var tuning = song.Tuning.ToShortArray();

            if (song.Levels != null)
            {
                foreach (var lvl in song.Levels)
                {
                    for (int i = 0; i + 1 <= lvl.Notes.Count(); i++)
                    {
                        var mNote = Sng2014FileWriter.GetMidiNote(tuning,
                                                                  (Byte)lvl.Notes[i].String,
                                                                  (Byte)lvl.Notes[i].Fret,
                                                                  song.Arrangement == "Bass",
                                                                  song.Capo);

                        midiNotes.Add(new Showlight()
                        {
                            Time = lvl.Notes[i].Time, Note = mNote
                        });
                    }
                    for (int i = 0; i + 1 <= lvl.Chords.Count(); i++)
                    {
                        if (lvl.Chords[i].HighDensity == 1)
                        {
                            continue; //speedhack
                        }
                        int mNote = Sng2014FileWriter.getChordNote(tuning,
                                                                   lvl.Chords[i], song.ChordTemplates,
                                                                   song.Arrangement == "Bass",
                                                                   song.Capo);

                        chordNotes.Add(new Showlight()
                        {
                            Time = lvl.Chords[i].Time, Note = mNote
                        });
                    }
                }
            }

            ShowL.PopShList(midiNotes);
            ShowL.PopShList(chordNotes);
            ShowL.Count = ShowL.ShowlightList.Count;

            return(ShowL);
        }
        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);
            }
        }
Esempio n. 16
0
        public Song Song2014ToSong(Song2014 rs2014Song)
        {
            var rs1Song = new Song();

            AddSongMetadata(rs2014Song, rs1Song);
            AddElements(rs2014Song, rs1Song);
            AddDifferences(rs2014Song, rs1Song);

            return(rs1Song);
        }
Esempio n. 17
0
        public AttributesHeader2014(string arrangementFileName, Arrangement arrangement, DLCPackageData info, Platform platform)
        {
            IsVocal     = arrangement.ArrangementType == Sng.ArrangementType.Vocal;
            SongContent = (IsVocal) ? null : Song2014.LoadFromFile(arrangement.SongXml.File);
            var dlcName = info.Name.ToLower();

            var albumUrn = String.Format(URN_TEMPLATE, TagValue.Image.GetDescription(), TagValue.DDS.GetDescription(), String.Format("album_{0}", dlcName));
            var jsonUrn  = String.Format(URN_TEMPLATE, TagValue.Database.GetDescription(), TagValue.JsonDB.GetDescription(), String.Format("{0}_{1}", dlcName, arrangementFileName));

            //FILL ATTRIBUTES
            this.AlbumArt              = albumUrn;
            ArrangementName            = arrangement.Name.ToString();
            DLC                        = true;
            DLCKey                     = info.Name;
            LeaderboardChallengeRating = 0;
            ManifestUrn                = jsonUrn;
            MasterID_RDV               = arrangement.MasterId;
            PersistentID               = arrangement.Id.ToString().Replace("-", "").ToUpper();
            Shipping                   = true;
            SKU                        = "RS2";
            SongKey                    = info.Name;

            if (!IsVocal)
            {
                AlbumName      = AlbumNameSort = info.SongInfo.Album;
                ArtistName     = info.SongInfo.Artist;
                CentOffset     = arrangement.TuningPitch != 0 ? TuningFrequency.Frequency2Cents(arrangement.TuningPitch) : 0.0;
                ArtistNameSort = info.SongInfo.ArtistSort;
                CapoFret       = (arrangement.Sng2014.Metadata.CapoFretId == 0xFF) ? CapoFret = 0 : Convert.ToDecimal(arrangement.Sng2014.Metadata.CapoFretId);
                DNA_Chords     = arrangement.Sng2014.DNACount[(int)DNAId.Chord];
                DNA_Riffs      = arrangement.Sng2014.DNACount[(int)DNAId.Riff];
                DNA_Solo       = arrangement.Sng2014.DNACount[(int)DNAId.Solo];
                NotesEasy      = arrangement.Sng2014.NoteCount[0];
                NotesMedium    = arrangement.Sng2014.NoteCount[1];
                NotesHard      = arrangement.Sng2014.NoteCount[2];
                EasyMastery    = NotesEasy / NotesHard;
                MediumMastery  = NotesMedium / NotesHard;
                Representative = Convert.ToInt32(!arrangement.BonusArr);
                RouteMask      = (int)arrangement.RouteMask;

                // TODO this is not quite it but much closer
                SongDiffEasy   = SongContent.SongLength / NotesEasy;
                SongDiffMed    = SongContent.SongLength / NotesMedium;
                SongDiffHard   = SongContent.SongLength / NotesHard;
                SongDifficulty = SongDiffHard;

                SongLength   = (double?)Math.Round(SongContent.SongLength, 3, MidpointRounding.AwayFromZero);
                SongName     = info.SongInfo.SongDisplayName;
                SongNameSort = info.SongInfo.SongDisplayNameSort;
                SongYear     = info.SongInfo.SongYear;

                var tunDef = TuningDefinitionRepository.Instance().Select(arrangement.Tuning, platform.version);
                Tuning = tunDef.Tuning;
            }
        }
        private void convertSngXmlButton_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(ConverterSngXmlFile))
            {
                MessageBox.Show(String.Format("File not found: {0}: ", ConverterSngXmlFile), MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                sngXmlTB.Focus();
                return;
            }

            if (sng2xmlRadio.Checked)
            {
                if (String.IsNullOrEmpty(ConverterManifestFile))
                {
                    MessageBox.Show("No manifest file was entered. The song xml file will be generated without song informations like song title, album, artist, tone names, etc.", MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                Attributes2014 att = null;
                if (ConverterArrangementType != ArrangementType.Vocal && !String.IsNullOrEmpty(ConverterManifestFile))
                {
                    att = Manifest2014 <Attributes2014> .LoadFromFile(ConverterManifestFile).Entries.ToArray()[0].Value.ToArray()[0].Value;
                }

                var sng = Sng2014File.LoadFromFile(ConverterSngXmlFile, ConverterPlatform);

                var outputFile = Path.Combine(Path.GetDirectoryName(ConverterSngXmlFile), String.Format("{0}.xml", Path.GetFileNameWithoutExtension(ConverterSngXmlFile)));
                using (FileStream outputStream = new FileStream(outputFile, FileMode.Create, FileAccess.ReadWrite))
                {
                    dynamic xml = null;

                    if (ConverterArrangementType == ArrangementType.Vocal)
                    {
                        xml = new Vocals(sng);
                    }
                    else
                    {
                        xml = new Song2014(sng, att ?? null);
                    }

                    xml.Serialize(outputStream);

                    MessageBox.Show(String.Format("XML file was generated! {0}It was saved on same location of sng file specified.", Environment.NewLine), MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else if (xml2sngRadio.Checked)
            {
                var outputFile = Path.Combine(Path.GetDirectoryName(ConverterSngXmlFile), String.Format("{0}.sng", Path.GetFileNameWithoutExtension(ConverterSngXmlFile)));

                using (FileStream outputStream = new FileStream(outputFile, FileMode.Create, FileAccess.ReadWrite)) {
                    Sng2014File sng = Sng2014File.ConvertXML(ConverterSngXmlFile, ConverterArrangementType);
                    sng.WriteSng(outputStream, ConverterPlatform);
                }

                MessageBox.Show(String.Format("SNG file was generated! {0}It was saved on same location of xml file specified.", Environment.NewLine), MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private static void UpdateTones(Arrangement arrangement)
        {
            // template may not reflect current XML state, update tone slots
            if (arrangement.ArrangementType != ArrangementType.Vocal)
            {
                var xml = Song2014.LoadFromFile(arrangement.SongXml.File);

                if (xml.ToneBase != null)
                {
                    arrangement.ToneBase = xml.ToneBase;
                }

                // A (ID 0)
                if (xml.ToneA != null)
                {
                    if (xml.ToneA != xml.ToneBase)
                    {
                        // SNG convertor expects ToneA to be ID 0
                        throw new InvalidDataException(String.Format("Invalid tone definition detected in {0}, ToneA (ID 0) is expected to be same as ToneBase.", arrangement.SongXml.File));
                    }
                    arrangement.ToneA = xml.ToneA;
                }
                else
                {
                    arrangement.ToneA = null;
                }
                // B (ID 1)
                if (xml.ToneB != null)
                {
                    arrangement.ToneB = xml.ToneB;
                }
                else
                {
                    arrangement.ToneB = null;
                }
                // C (ID 2)
                if (xml.ToneC != null)
                {
                    arrangement.ToneC = xml.ToneC;
                }
                else
                {
                    arrangement.ToneC = null;
                }
                // D (ID 3)
                if (xml.ToneD != null)
                {
                    arrangement.ToneD = xml.ToneD;
                }
                else
                {
                    arrangement.ToneD = null;
                }
            }
        }
Esempio n. 20
0
 private void AddElements(Song2014 rs2014Song, Song rs1Song)
 {
     // these elements have direct mapping
     rs1Song.Phrases               = rs2014Song.Phrases;
     rs1Song.LinkedDiffs           = rs2014Song.LinkedDiffs;
     rs1Song.PhraseProperties      = rs2014Song.PhraseProperties;
     rs1Song.FretHandMuteTemplates = rs2014Song.FretHandMuteTemplates;
     rs1Song.Ebeats   = rs2014Song.Ebeats;
     rs1Song.Sections = rs2014Song.Sections;
     rs1Song.Events   = rs2014Song.Events;
 }
Esempio n. 21
0
        // this is platform independent SNG object
        public static Sng2014File ConvertSong(string xmlFile)
        {
            var song   = Song2014.LoadFromFile(xmlFile);
            var parser = new Sng2014FileWriter();
            var sng    = new Sng2014File();

            parser.ReadSong(song, sng);
            sng.NoteCount = parser.NoteCount;
            sng.DNACount  = parser.DNACount;
            return(sng);
        }
Esempio n. 22
0
        static void ExportXml(List <string> inputFiles, CmdOptions options)
        {
            Score  score      = new Score();
            string identifier = "none";

            foreach (var xmlFile in inputFiles)
            {
                Console.WriteLine("Processing {0} ...", xmlFile);
                Song2014 arrangement = null;
                try
                {
                    arrangement = Song2014.LoadFromFile(xmlFile);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to parse XML input file: " + e.Message);
                }

                if (arrangement != null)
                {
                    // xml files should be named "songidentifier_arrangement.xml",
                    // extract the arrangement identifier, which we use to set
                    // the track name and track color as well as output file name
                    string baseFileName = Path.GetFileNameWithoutExtension(xmlFile);
                    var    identifiers  = baseFileName.Split(new char[] { '_' });
                    string arr          = "";
                    if (identifiers.Length >= 2)
                    {
                        arr = identifiers.Last();
                    }
                    identifier = identifiers.First();

                    ExportArrangement(score, arrangement, arr, options.DifficultyLevel, xmlFile, null);
                    if (options.SplitArrangements)
                    {
                        baseFileName = CleanFileName(
                            ConstructFileName(options.FileNameFormat, score, identifier, identifier, null));
                        baseFileName += " (" + arr + ")";
                        SaveScore(score, baseFileName, options.OutputDirectory, options.OutputFormat);
                        // remember to remove the track from the score again
                        score.Tracks.Clear();
                    }
                }
            }

            if (!options.SplitArrangements)
            {
                score.SortTracks();
                string baseFileName = CleanFileName(
                    ConstructFileName(options.FileNameFormat, score, identifier, identifier, null));
                SaveScore(score, baseFileName, options.OutputDirectory, options.OutputFormat);
            }
        }
Esempio n. 23
0
        public Int32 GetMaxDifficulty(Song2014 xml)
        {
            var max = 0;

            foreach (var phrase in xml.Phrases)
            {
                if (max < phrase.MaxDifficulty)
                {
                    max = phrase.MaxDifficulty;
                }
            }
            return(max);
        }
Esempio n. 24
0
        /// <summary>
        /// Showlights Generator Rev3
        /// using arrangement and level with most notes and chords
        /// </summary>
        /// <param name="xmlFile">Xml file.</param>
        private void Generate(string xmlFile, int maxLevelNdx)
        {
            var midiNotes  = new List <Showlight>();
            var chordNotes = new List <Showlight>();
            var song       = Song2014.LoadFromFile(xmlFile);

            // error checking
            if (song.Phrases == null || song.Levels == null || song.Tuning == null)
            {
                throw new Exception("Arrangement: " + xmlFile + Environment.NewLine +
                                    "Contains no phrases, levels and/or tuning.");
            }

            // tuning used to get proper midi notes
            var tuning = song.Tuning.ToArray();

            foreach (var note in song.Levels[maxLevelNdx].Notes)
            {
                // make showlights changes occure on the beat/measure
                var measOffset = song.Ebeats.Where(eb => eb.Measure != -1 && eb.Time <= note.Time).Last();
                // forcing midi notes for guitar gives more consistent results even with bass arrangements
                var mNote = Sng2014FileWriter.GetMidiNote(tuning, (Byte)note.String, (Byte)note.Fret, false, song.Capo);
                // varying midi notes gives more color changes
                // var mNote = Sng2014FileWriter.GetMidiNote(tuning, (Byte)note.String, (Byte)note.Fret, song.Arrangement == "Bass", song.Capo);
                midiNotes.Add(new Showlight {
                    Time = measOffset.Time, Note = mNote
                });
            }

            foreach (var chord in song.Levels[maxLevelNdx].Chords)
            {
                if (chord.HighDensity == 1)
                {
                    continue; //speedhack
                }
                // make showlights occure on the beat/measure
                var measOffset = song.Ebeats.Where(eb => eb.Measure != -1 && eb.Time <= chord.Time).Last();
                // forcing midi notes for guitar gives more consistent results even with bass arrangements
                var mNote = Sng2014FileWriter.getChordNote(tuning, chord, song.ChordTemplates, false, song.Capo);
                // varying midi notes gives more color changes
                //var mNote = Sng2014FileWriter.getChordNote(tuning, chord, song.ChordTemplates, song.Arrangement == "Bass", song.Capo);
                chordNotes.Add(new Showlight {
                    Time = measOffset.Time, Note = mNote
                });
            }

            ShowlightList = new List <Showlight>();
            AddShowlights(midiNotes);
            AddShowlights(chordNotes);
        }
Esempio n. 25
0
        static int[] GetTuning(Song2014 arrangement)
        {
            // Guitar Pro expects the tuning as Midi note values
            // In Rocksmith, the tuning is given as the difference in half steps
            // from standard tuning for each string, so we need to convert that.
            bool isBass = arrangement.Title.ToLower() == "bass";

            int[] tuning = new int[6];
            for (byte s = 0; s < tuning.Length; ++s)
            {
                tuning[s] = Sng2014FileWriter.GetMidiNote(arrangement.Tuning.ToArray(), s, 0, isBass, 0);
            }
            return(tuning);
        }
        private Song2014 ConvertPhraseIterations(Song rsSong, Song2014 rsSong2014)
        {
            var phraseIterations = new List <SongPhraseIteration2014>();

            foreach (var songPhraseIteration in rsSong.PhraseIterations)
            {
                // HeroLevels set to null -> prevent some hangs
                phraseIterations.Add(new SongPhraseIteration2014 {
                    PhraseId = songPhraseIteration.PhraseId, HeroLevels = null, Time = songPhraseIteration.Time
                });
            }
            rsSong2014.PhraseIterations = phraseIterations.ToArray();

            return(rsSong2014);
        }
        private static void UpdateManifest2014(string songDirectory, Platform platform)
        {
            // UPDATE MANIFEST (RS2014)
            if (platform.version == GameVersion.RS2014)
            {
                var xmlFiles  = Directory.EnumerateFiles(songDirectory, "*.xml", SearchOption.AllDirectories);
                var jsonFiles = Directory.EnumerateFiles(songDirectory, "*.json", SearchOption.AllDirectories);
                foreach (var xml in xmlFiles)
                {
                    var xmlName = Path.GetFileNameWithoutExtension(xml);
                    if (xmlName.ToUpperInvariant().Contains("SHOWLIGHT"))
                    {
                        continue;
                    }
                    if (xmlName.ToUpperInvariant().Contains("VOCAL"))
                    {
                        continue;//TODO: Re-generate vocals manifest.
                    }
                    string json = jsonFiles.Where(name => Path.GetFileNameWithoutExtension(name) == xmlName).FirstOrDefault();
                    if (!String.IsNullOrEmpty(json))
                    {
                        var xmlContent = Song2014.LoadFromFile(xml);
                        var manifest   = new Manifest2014 <Attributes2014>();
                        var attr       = Manifest2014 <Attributes2014> .LoadFromFile(json).Entries.First().Value.First().Value;

                        var manifestFunctions = new ManifestFunctions(platform.version);

                        attr.PhraseIterations = new List <Manifest.PhraseIteration>();
                        manifestFunctions.GeneratePhraseIterationsData(attr, xmlContent, platform.version);

                        attr.Phrases = new List <Manifest.Phrase>();
                        manifestFunctions.GeneratePhraseData(attr, xmlContent);

                        attr.Sections = new List <Manifest.Section>();
                        manifestFunctions.GenerateSectionData(attr, xmlContent);

                        attr.MaxPhraseDifficulty = manifestFunctions.GetMaxDifficulty(xmlContent);

                        var attributeDictionary = new Dictionary <string, Attributes2014> {
                            { "Attributes", attr }
                        };
                        manifest.Entries.Add(attr.PersistentID, attributeDictionary);
                        manifest.SaveToFile(json);
                    }
                }
            }
        }
Esempio n. 28
0
        /// <summary>
        /// Showlights Generator Rev2
        /// max difficulty with most notes and chords
        /// </summary>
        /// <param name="xmlFile">Xml file.</param>
        public Showlights Generate(string xmlFile)
        {
            var midiNotes  = new List <Showlight>();
            var chordNotes = new List <Showlight>();
            var song       = Song2014.LoadFromFile(xmlFile);

            // If vocals
            if (song.Phrases == null || song.Tuning == null)
            {
                return(null);
            }
            //Generate ShowlightList
            var tuning = song.Tuning.ToArray();

            if (song.Levels != null)
            {
                var mf     = new ManifestFunctions(GameVersion.RS2014);
                int maxDif = mf.GetMaxDifficulty(song);

                for (int i = 0; i < song.Levels[maxDif].Notes.Length; i++)
                {
                    var mNote = Sng2014FileWriter.GetMidiNote(tuning, (Byte)song.Levels[maxDif].Notes[i].String, (Byte)song.Levels[maxDif].Notes[i].Fret, song.Arrangement == "Bass", song.Capo);
                    midiNotes.Add(new Showlight {
                        Time = song.Levels[maxDif].Notes[i].Time, Note = mNote
                    });
                }

                for (int i = 0; i < song.Levels[maxDif].Chords.Length; i++)
                {
                    if (song.Levels[maxDif].Chords[i].HighDensity == 1)
                    {
                        continue; //speedhack
                    }
                    int mNote = Sng2014FileWriter.getChordNote(tuning, song.Levels[maxDif].Chords[i], song.ChordTemplates, song.Arrangement == "Bass", song.Capo);
                    chordNotes.Add(new Showlight {
                        Time = song.Levels[maxDif].Chords[i].Time, Note = mNote
                    });
                }
            }

            PopShList(midiNotes);
            PopShList(chordNotes);

            return(this);
        }
Esempio n. 29
0
        public void CreateShowlights(DLCPackageData info)
        {
            int maxNoteChordCount = 0;
            int maxArrNdx         = 0;
            int maxLevelNdx       = 0;

            // find arrangment with most notes and chords
            for (int i = 0; i < info.Arrangements.Count; i++)
            {
                if (info.Arrangements[i].ArrangementType == ArrangementType.Vocal)
                {
                    continue;
                }
                if (info.Arrangements[i].ArrangementType == ArrangementType.ShowLight)
                {
                    continue;
                }
                if (info.Arrangements[i].SongXml.File == null)
                {
                    continue;
                }

                var song = Song2014.LoadFromFile(info.Arrangements[i].SongXml.File);

                // find level with most notes and chords
                for (int j = 0; j < song.Levels.Count(); j++)
                {
                    int noteCount      = song.Levels[j].Notes.Count();
                    int chordCount     = song.Levels[j].Chords.Count();
                    int noteChordCount = noteCount + chordCount;

                    if (noteChordCount > maxNoteChordCount)
                    {
                        maxNoteChordCount = noteChordCount;
                        maxArrNdx         = i;
                        maxLevelNdx       = j;
                    }
                }
            }

            Generate(info.Arrangements[maxArrNdx].SongXml.File, maxLevelNdx);
            AdjustShowlights(ShowlightList, info.DefaultShowlights);
            Count = ShowlightList.Count;
        }
        public static void GetSongDifficulty(AttributesHeader2014 attribute, Song2014 song)
        {
            var easyArray   = new List <int>();
            var mediumArray = new List <int>();
            var hardArray   = new List <int>();

            for (int i = 0; i < song.PhraseIterations.Length; i++)
            {
                var pt   = song.PhraseIterations[i];
                var hard = song.Phrases[pt.PhraseId].MaxDifficulty;
                if (pt.HeroLevels != null)
                {
                    foreach (var h in pt.HeroLevels)
                    {
                        switch (h.Hero)
                        {
                        case 1:
                            easyArray.Add(h.Difficulty);
                            break;

                        case 2:
                            mediumArray.Add(h.Difficulty);
                            break;

                        case 3:
                            hard = h.Difficulty;
                            break;
                        }
                        hardArray.Add(hard);
                    }
                }
            }

            // Is not the way of official are calculated, but is a way to calculate unique values for custom
            // Could be rewritten with the correct way or a best way to get this value
            var itCount = song.PhraseIterations.Length;
            var ifAny   = easyArray.Count > 0;

            // TODO: round to 9 decimal places and improve calculation
            attribute.SongDiffEasy   = ifAny ? easyArray.Average() / itCount : 0;
            attribute.SongDiffMed    = ifAny ? mediumArray.Average() / itCount : 0;
            attribute.SongDiffHard   = ifAny ? hardArray.Average() / itCount : 0;
            attribute.SongDifficulty = attribute.SongDiffHard;
        }