private static void generateManifest(Stream outManifest, Tone tone)
 {
     var manifest = new Manifest.Tone.Manifest();
     manifest.Entries.Add(tone);
     var data = JsonConvert.SerializeObject(manifest, Formatting.Indented);
     var writer = new StreamWriter(outManifest);
     writer.Write(data);
     writer.Flush();
     outManifest.Seek(0, SeekOrigin.Begin);
 }
        public static void Generate(string toneKey, Tone tone, Stream outManifest, Stream outXblock, Stream aggregateGraph)
        {
            var id = IdGenerator.Guid().ToString().Replace("-", "");
            if (string.IsNullOrEmpty(tone.Name))
                tone.Name = toneKey;
            tone.Key = toneKey;
            tone.PersistentID = id;
            tone.BlockAsset = String.Format("urn:emergent-world:DLC_Tone_{0}", toneKey);

            generateManifest(outManifest, tone);
            generateXBlock(toneKey, outXblock, tone);
            generateAggregateGraph(toneKey, aggregateGraph);
        }
 private static void generateXBlock(string toneKey, Stream outXblock, Tone tone)
 {
     var game = new GameXblock<Entity>();
     var entity = new Entity
     {
         Name = String.Format("GRTonePreset_{0}", toneKey),
         Iterations = 1,
         ModelName = "GRTonePreset",
         Id = tone.PersistentID.ToLower()
     };
     var properties = entity.Properties = new List<Property>();
     var addProperty = new Action<string, object>((a, b) => properties.Add(CreateProperty(a, b.ToString())));
     addProperty("Key", tone.Key);
     addProperty("Name", tone.Name);
     game.EntitySet = new List<Entity> {entity};
     game.Serialize(outXblock);
 }
        public Tone2014 ToneToTone2014(Tone rs1Tone, Song rs1Song)
        {
            Tone2014 tone2014 = new Tone2014();
            Pedal2014 amp = new Pedal2014();
            Pedal2014 cabinet = new Pedal2014();
            Pedal2014 prepedal1 = new Pedal2014();
            Pedal2014 rack1 = new Pedal2014();
            Pedal2014 rack2 = new Pedal2014();
            tone2014.ToneDescriptors = new List<string>();
            // use Tone Key for better conversion
            tone2014.Name = rs1Tone.Name ?? "Default";
            tone2014.Key = rs1Tone.Key ?? "DEFAULT";
            tone2014.Volume = rs1Tone.Volume;
            tone2014.IsCustom = true;
            tone2014.NameSeparator = " - ";
            tone2014.SortOrder = 0;

            // setup some possible tone approximation conversions
            // no direct mapping for RS1 -> RS2 Tones
            // look here IEnumerable<ToneDescriptor> List()
            // TODO: figure out better method for tone mapping
            if (tone2014.Key.ToUpper().Contains("COMBO"))
                tone2014.Key = "Combo_OD";

            if (tone2014.Key.ToUpper().Contains("OD"))
            {
                tone2014.ToneDescriptors.Add("$[35716]OVERDRIVE");
                amp.Type = "Amps";
                amp.Category = "Amp";
                amp.PedalKey = "Amp_MarshallJTM45";
                cabinet.Type = "Cabinets";
                cabinet.Category = "Dynamic_Cone";
                cabinet.PedalKey = "Cab_Marshall1936_57_Cone";
                rack1.Type = "Racks";
                rack1.Category = "Filter";
                rack1.PedalKey = "Rack_StudioEQ";
                rack2.Type = "Racks";
                rack2.Category = "Reverb";
                rack2.PedalKey = "Rack_StudioVerb";
                prepedal1.Type = "Pedals";
                prepedal1.Category = "Distortion";
                prepedal1.PedalKey = "Pedal_SuperDrive";

                tone2014.GearList = new Gear2014()
                {
                    Amp = amp,
                    Cabinet = cabinet,
                    Rack1 = rack1,
                    Rack2 = rack2,
                    PrePedal1 = prepedal1
                };
            }
            else if (tone2014.Key.ToUpper().Contains("LEAD"))
            {
                tone2014.ToneDescriptors.Add("$[35724]LEAD");
                amp.Type = "Amps";
                amp.Category = "Amp";
                amp.PedalKey = "Amp_AT120";
                cabinet.Type = "Cabinets";
                cabinet.Category = "Dynamic_Cone";
                cabinet.PedalKey = "Cab_OrangePPC412_57_Cone";
                rack1.Type = "Racks";
                rack1.Category = "Filter";
                rack1.PedalKey = "Rack_StudioEQ";
                prepedal1.Type = "Pedals";
                prepedal1.Category = "Distortion";
                prepedal1.PedalKey = "Pedal_GermaniumDrive";

                tone2014.GearList = new Gear2014()
                {
                    Amp = amp,
                    Cabinet = cabinet,
                    Rack1 = rack1,
                    PrePedal1 = prepedal1
                };
            }
            else if (tone2014.Key.ToUpper().Contains("DIS"))
            {
                tone2014.ToneDescriptors.Add("$[35722]DISTORTION");
                amp.Type = "Amps";
                amp.Category = "Amp";
                amp.PedalKey = "Amp_GB100";
                cabinet.Type = "Cabinets";
                cabinet.Category = "Dynamic_Cone";
                cabinet.PedalKey = "Cab_GB412CMKIII_57_Cone";
                rack1.Type = "Racks";
                rack1.Category = "Filter";
                rack1.PedalKey = "Rack_StudioEQ";
                rack2.Type = "Racks";
                rack2.Category = "Reverb";
                rack2.PedalKey = "Rack_StudioVerb";
                prepedal1.Type = "Pedals";
                prepedal1.Category = "Distortion";
                prepedal1.PedalKey = "Pedal_GermaniumDrive";

                tone2014.GearList = new Gear2014()
                {
                    Amp = amp,
                    Cabinet = cabinet,
                    Rack1 = rack1,
                    Rack2 = rack2,
                    PrePedal1 = prepedal1
                };
            }
            else if (tone2014.Key.ToUpper().Contains("CLEAN"))
            {
                tone2014.ToneDescriptors.Add("$[35720]CLEAN");
                amp.Type = "Amps";
                amp.Category = "Amp";
                amp.PedalKey = "Amp_TW40";
                cabinet.Type = "Cabinets";
                cabinet.Category = "Dynamic_Cone";
                cabinet.PedalKey = "Cab_TW112C_57_Cone";
                rack1.Type = "Racks";
                rack1.Category = "Filter";
                rack1.PedalKey = "Rack_StudioEQ";

                tone2014.GearList = new Gear2014()
                {
                    Amp = amp,
                    Cabinet = cabinet,
                    Rack1 = rack1
                };
            }
            else if (tone2014.Key.ToUpper().Contains("ACOU"))
            {
                tone2014.ToneDescriptors.Add("$[35721]ACOUSTIC");
                amp.Type = "Amps";
                amp.Category = "Amp";
                amp.PedalKey = "Amp_TW40";
                cabinet.Type = "Cabinets";
                cabinet.Category = "Dynamic_Cone";
                cabinet.PedalKey = "Cab_GB412CMKIII_57_Cone";
                rack1.Type = "Racks";
                rack1.Category = "Filter";
                rack1.PedalKey = "Rack_StudioEQ";
                rack2.Type = "Racks";
                rack2.Category = "Dynamics";
                rack2.PedalKey = "Rack_StudioCompressor";
                prepedal1.Type = "Pedals";
                prepedal1.Category = "Filter";
                prepedal1.PedalKey = "Pedal_AcousticEmulator";

                tone2014.GearList = new Gear2014()
                {
                    Amp = amp,
                    Cabinet = cabinet,
                    Rack1 = rack1,
                    Rack2 = rack2,
                    PrePedal1 = prepedal1
                };
            }
            else if (tone2014.Key.ToUpper().Contains("BASS"))
            {
                tone2014.ToneDescriptors.Add("$[35715]BASS");
                amp.Type = "Amps";
                amp.Category = "Amp";
                amp.PedalKey = "Bass_Amp_CH300B";
                cabinet.Type = "Cabinets";
                cabinet.Category = "Dynamic_Cone";
                cabinet.PedalKey = "Bass_Cab_BT410BC_57_Cone";
                rack1.Type = "Racks";
                rack1.Category = "Filter";
                rack1.PedalKey = "Rack_StudioEQ";

                tone2014.GearList = new Gear2014() { Amp = amp, Cabinet = cabinet, Rack1 = rack1 };
            }
            else // default acoustic is better than nothing
            {
                // this is fix for bad RS1 CDLC tones
                tone2014.Key = "DEFAULT";
                //
                tone2014.ToneDescriptors.Add("$[35721]ACOUSTIC");
                amp.Type = "Amps";
                amp.Category = "Amp";
                amp.PedalKey = "Amp_TW40";
                cabinet.Type = "Cabinets";
                cabinet.Category = "Dynamic_Cone";
                cabinet.PedalKey = "Cab_GB412CMKIII_57_Cone";
                rack1.Type = "Racks";
                rack1.Category = "Filter";
                rack1.PedalKey = "Rack_StudioEQ";
                rack2.Type = "Racks";
                rack2.Category = "Dynamics";
                rack2.PedalKey = "Rack_StudioCompressor";
                prepedal1.Type = "Pedals";
                prepedal1.Category = "Filter";
                prepedal1.PedalKey = "Pedal_AcousticEmulator";

                tone2014.GearList = new Gear2014()
                {
                    Amp = amp,
                    Cabinet = cabinet,
                    Rack1 = rack1,
                    Rack2 = rack2,
                    PrePedal1 = prepedal1
                };
            }

            return tone2014;
        }
        private static void GenerateTonePsarc(Stream output, string toneKey, Tone tone)
        {
            var tonePsarc = new PSARC.PSARC();

            using (var packageIdStream = new MemoryStream())
            using (var toneManifestStream = new MemoryStream())
            using (var toneXblockStream = new MemoryStream())
            using (var toneAggregateGraphStream = new MemoryStream())
            {
                ToneGenerator.Generate(toneKey, tone, toneManifestStream, toneXblockStream, toneAggregateGraphStream);
                GenerateTonePackageId(packageIdStream, toneKey);
                tonePsarc.AddEntry(String.Format("Exports/Pedals/DLC_Tone_{0}.xblock", toneKey), toneXblockStream);
                var x = (tone.PedalList.Where(pedal => pedal.Value.PedalKey.ToLower().Contains("bass"))).Count();
                tonePsarc.AddEntry(x > 0 ? "Manifests/tone_bass.manifest.json" : "Manifests/tone.manifest.json", toneManifestStream);
                tonePsarc.AddEntry("AggregateGraph.nt", toneAggregateGraphStream);
                tonePsarc.AddEntry("PACKAGE_ID", packageIdStream);
                tonePsarc.Write(output, false);
                output.Flush();
                output.Seek(0, SeekOrigin.Begin);
            }
        }