Beispiel #1
0
        private List <ZObject> CreateSongObjects(FusedSong input)
        {
            List <ZObject> objects       = new List <ZObject>();
            HKey           songDirectory = "songs." + input.Identifier;

            // Create song object
            Song song = new Song(songDirectory + ".song", songDirectory)
            {
                Title       = input.Title,
                Artist      = input.Artist,
                Description = input.Description,
                Album       = input.Album,

                LegendTag = "Tags.Legends.NoLegend.Tag",
                EraTag    = "Tags.Eras.Timeless.Tag",
                Year      = input.Year,

                GuitarIntensity = input.GuitarIntensity,
                BassIntensity   = input.BassIntensity,
                VoxIntensity    = input.BassIntensity,

                SongLength = input.SongLength
            };

            // Imports note tracks
            // TODO: Check if RB import vs custom spec
            MIDIImport mid    = new MIDIImport(GetFilePath(input.TabPath));
            var        tracks = mid.ExportZObjects(songDirectory, input.LeadGuitarTuning, input.RhythmGuitarTuning, input.BassTuning);

            // Adds instrument file paths
            foreach (ZObject instrument in tracks.Where(x => x is Instrument))
            {
                song.InstrumentPaths.Add(instrument.FilePath);
            }

            objects.AddRange(tracks);

            // Adds audio paths
            song.PreviewPath           = songDirectory + ".preview.audio";
            song.BackingAudioPath      = songDirectory + ".gamestems.back.audio";
            song.BassAudioPath         = songDirectory + ".gamestems.bass.audio";
            song.DrumsAudioPath        = songDirectory + ".gamestems.drums.audio";
            song.LeadGuitarAudioPath   = songDirectory + ".gamestems.gtr1.audio";
            song.RhythmGuitarAudioPath = songDirectory + ".gamestems.gtr2.audio";
            song.VoxAudioPath          = songDirectory + ".gamestems.vox.audio";

            // Adds video path
            song.VideoPath = songDirectory + ".musicvideo.video";

            // Create texture path
            // TODO: Add texture conversion
            //song.TexturePath = songDirectory + ".texture";
            song.TexturePath = "textures.albumart.bandfuse.originalcontent.texture";

            // Adds tags
            song.Labels.Add("BFForever");
            song.GenreTags.Add("Tags.Genres.rock.Tag"); // TODO: Read from json input
            song.MetadataTags = CreateMetadataTags(song);

            objects.Add(song);
            return(objects);
        }
Beispiel #2
0
        public void ImportSong(string jsonPath)
        {
            _jsonDirectory = Path.GetDirectoryName(jsonPath) + "\\";
            FusedSong fusedSong = FusedSong.Import(jsonPath);

            // Updates tuning info
            fusedSong.LeadGuitarTuning   = UpdateTuning(fusedSong.LeadGuitarTuning, true);
            fusedSong.RhythmGuitarTuning = UpdateTuning(fusedSong.RhythmGuitarTuning, true);
            fusedSong.BassTuning         = UpdateTuning(fusedSong.BassTuning, false);

            // Create song objects
            List <ZObject> songObjects = CreateSongObjects(fusedSong);
            Song           song        = songObjects.First(x => x is Song) as Song;

            // Create audio stem paths
            void CreateAudioPath(HKey path)
            {
                // Creates audio object
                Riff.Audio audio = new Riff.Audio(path, path.GetParentDirectory());
                audio.AudioPath = audio.FilePath + ".clt";

                // Adds audio object song objects
                songObjects.Add(audio);

                // Adds celt to index
                AddFileToIndex(audio.AudioPath, "clt", audio.FilePath.Value.Replace(".", "/") + ".clt");
            }

            CreateAudioPath(song.PreviewPath);
            CreateAudioPath(song.BackingAudioPath);
            CreateAudioPath(song.BassAudioPath);
            CreateAudioPath(song.DrumsAudioPath);
            CreateAudioPath(song.LeadGuitarAudioPath);
            CreateAudioPath(song.RhythmGuitarAudioPath);
            CreateAudioPath(song.VoxAudioPath);

            // Create video path
            Video video = new Video(song.VideoPath, song.VideoPath.GetParentDirectory());

            video.VideoPath = video.FilePath + ".bik";
            songObjects.Add(video);

            AddFileToIndex(video.VideoPath, "bik", video.FilePath.Value.Replace(".", "/") + ".bik");

            // Create texture path
            // TODO: Add texture conversion

            /*
             * Riff.Texture texture = new Riff.Texture(song.TexturePath, song.TexturePath.GetParentDirectory());
             * texture.TexturePath = texture.DirectoryPath + ".album.xpr";
             * //songObjects.Add(texture); // Don't write to index
             *
             * AddFileToIndex(texture.FilePath, "texture", texture.DirectoryPath.Value.Replace(".", "/") + "/album.xpr");
             */

            // Adds song to catalog
            AddToCatalog(song, fusedSong.LeadGuitarTuning, fusedSong.RhythmGuitarTuning, fusedSong.BassTuning);

            string realPath = song.DirectoryPath.Value.Replace(".", "/");

            AddObjectsToIndex(songObjects, realPath + "/fused.rif");

            _packageManager.AddZObjectsAsPending(songObjects);
            _packageManager.SavePendingChanges();

            // Copies files over to song directory
            void CopyFile(string input, string output)
            {
                if (input == null || !File.Exists(input))
                {
                    return;
                }

                string outPath = Path.Combine(_packageManager.CurrentPackageDirectory + "\\songs\\", fusedSong.Identifier.Replace(".", "\\") + "\\" + output);

                // Creates directory
                if (!Directory.Exists(Path.GetDirectoryName(outPath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(outPath));
                }

                File.Copy(input, outPath, true);
            }

            //CopyFile(GetFilePath(fusedSong.TexturePath), "album.xpr");
            CopyFile(GetFilePath(fusedSong.VideoPath), "musicvideo\\video.bik");

            if (fusedSong.AudioPaths == null)
            {
                return;
            }

            EncodeAudio(fusedSong);
        }
Beispiel #3
0
        private void EncodeAudio(FusedSong song)
        {
            string mapPath = GetFilePath("hashes.json");

            // Imports existing mappings if found
            AudioHashMappings audioMap = File.Exists(mapPath)
                ? AudioHashMappings.Import(mapPath)
                : new AudioHashMappings();

            string GetPackageFilePath(string relativePath) =>
            Path.Combine(_packageManager.CurrentPackageDirectory + "\\songs\\", song.Identifier.Replace(".", "\\") + "\\" + relativePath);

            bool IsCeltFile(string path)
            {
                string ext = Path.GetExtension(path);

                return(ext.Equals(".clt", StringComparison.CurrentCultureIgnoreCase));
            }

            HashMapping EncodeAudio(string input, string output, HashMapping oldMap)
            {
                if (!File.Exists(input))
                {
                    // Delete if no input
                    if (File.Exists(output))
                    {
                        File.Delete(output);
                    }

                    return(oldMap);
                }
                else if (!File.Exists(output))
                {
                    // Encodes audio (Import from celt supported)
                    Celt celt = IsCeltFile(input) ? Celt.FromFile(input) : Celt.FromAudio(input);
                    celt.Export(output);

                    // Updates hashes
                    return(HashMapping.CreateMapping(input, output));
                }

                HashMapping newMap = HashMapping.CreateMapping(input, output);

                if (newMap.Input != oldMap.Input || newMap.Output != oldMap.Output)
                {
                    // Encodes audio
                    Celt celt = IsCeltFile(input) ? Celt.FromFile(input) : Celt.FromAudio(input);
                    celt.Export(output);

                    // Updates output hash
                    newMap.Output = HashMapping.ComputeHashFromFile(output);
                }
                // Else means they're equal, no need to re-encode

                // Returns new hashes
                return(newMap);
            }

            audioMap.Preview      = EncodeAudio(GetFilePath(song.AudioPaths.Preview), GetPackageFilePath("preview\\audio.clt"), audioMap.Preview);
            audioMap.Backing      = EncodeAudio(GetFilePath(song.AudioPaths.Backing), GetPackageFilePath("gamestems\\back\\audio.clt"), audioMap.Backing);
            audioMap.Bass         = EncodeAudio(GetFilePath(song.AudioPaths.Bass), GetPackageFilePath("gamestems\\bass\\audio.clt"), audioMap.Bass);
            audioMap.Drums        = EncodeAudio(GetFilePath(song.AudioPaths.Drums), GetPackageFilePath("gamestems\\drums\\audio.clt"), audioMap.Drums);
            audioMap.LeadGuitar   = EncodeAudio(GetFilePath(song.AudioPaths.LeadGuitar), GetPackageFilePath("gamestems\\gtr1\\audio.clt"), audioMap.LeadGuitar);
            audioMap.RhythmGuitar = EncodeAudio(GetFilePath(song.AudioPaths.RhythmGuitar), GetPackageFilePath("gamestems\\gtr2\\audio.clt"), audioMap.RhythmGuitar);
            audioMap.Vox          = EncodeAudio(GetFilePath(song.AudioPaths.Vox), GetPackageFilePath("gamestems\\vox\\audio.clt"), audioMap.Vox);

            audioMap.Export(mapPath);
        }