コード例 #1
0
        /// <summary>
        /// Play a sequence.
        /// </summary>
        /// <param name="a">Sound archive.</param>
        /// <param name="sequenceNumber">Sequence number to play.</param>
        public static void PlaySequence(SoundArchive a, int sequenceNumber)
        {
            //Set info.
            Paused  = false;
            Stopped = false;

            MessageBox.Show("Not implemented yet, sowwy. :{");
        }
コード例 #2
0
ファイル: BankGenerator.cs プロジェクト: cruuud/NitroStudio2
 /// <summary>
 /// Populate a combo box with banks.
 /// </summary>
 /// <param name="a">The sound archive.</param>
 /// <param name="c">The combo box.</param>
 public static void PopulateBankBox(SoundArchive a, DataGridViewComboBoxColumn c)
 {
     c.Items.Clear();
     foreach (var w in a.Banks.Where(x => x.File.Instruments.Count > 0))
     {
         c.Items.Add("[" + w.Index + "] - " + w.Name);
     }
 }
コード例 #3
0
        /// <summary>
        /// Create a Nitro Studio 2 Instrument.
        /// </summary>
        /// <param name="inst">The instrument.</param>
        /// <param name="s">Sound archive.</param>
        /// <param name="war0">Wave archive 0.</param>
        /// <param name="war1">Wave archive 1.</param>
        /// <param name="war2">Wave archive 2.</param>
        /// <param name="war3">Wave archive 3.</param>
        public NitroStudio2Instrument(Instrument inst, SoundArchive s, ushort war0, ushort war1, ushort war2, ushort war3)
        {
            //Set instrument.
            Inst = inst;

            //No archive.
            if (s == null)
            {
                return;
            }

            //Load waves.
            Waves = new List <WaveEntry>();
            foreach (var n in inst.NoteInfo)
            {
                WaveEntry w = new WaveEntry();
                w.WaveId = n.WaveId;
                if (n.InstrumentType != InstrumentType.PCM)
                {
                    continue;
                }
                switch (n.WarId)
                {
                case 0:
                    n.WarId = w.WarId = war0;
                    break;

                case 1:
                    n.WarId = w.WarId = war1;
                    break;

                case 2:
                    n.WarId = w.WarId = war2;
                    break;

                case 3:
                    n.WarId = w.WarId = war3;
                    break;
                }
                if (n.WarId != 0xFFFF)
                {
                    var war = s.WaveArchives.Where(x => x.Index == (int)n.WarId).FirstOrDefault();
                    if (war != null)
                    {
                        w.Wave = war.File.Waves[n.WaveId];
                    }
                }
                Waves.Add(w);
            }
        }
コード例 #4
0
        /// <summary>
        /// Play a WSD entry.
        /// </summary>
        /// <param name="a">Sound archive.</param>
        /// <param name="wsdNumber">WSD entry to play.</param>
        public static void PlayWsd(SoundArchive a, int wsdNumber)
        {
            //Try playing.
            Stop();
            try {
                //WSD.
                WaveSoundData s = a.WaveSoundDatas[wsdNumber].File.File as WaveSoundData;
                var           p = s.Waves[s.DataItems[a.WaveSoundDatas[wsdNumber].WaveIndex].Notes[0].WaveIndex];
                Wave          w = (a.WaveArchives[p.WarIndex].File.File as SoundWaveArchive)[p.WaveIndex];
                if (w.Wav.info.channelInfo.Count > 2)
                {
                    switch (w.Wav.info.encoding)
                    {
                    case 0:
                        w.Wav.data.pcm8 = new sbyte[][] { w.Wav.data.pcm8[0], w.Wav.data.pcm8[1] };
                        break;

                    case 1:
                        w.Wav.data.pcm16 = new short[][] { w.Wav.data.pcm16[0], w.Wav.data.pcm16[1] };
                        break;

                    case 2:
                        w.Wav.data.dspAdpcm = new byte[][] { w.Wav.data.dspAdpcm[0], w.Wav.data.dspAdpcm[1] };
                        break;
                    }
                }
                for (int i = 2; i < w.Wav.info.channelInfo.Count; i++)
                {
                    w.Wav.info.channelInfo.RemoveAt(i);
                }
                var m = new MemoryStream(w.Riff.ToBytes());
                var n = new WaveFileReader(m);
                waveOut.Initialize(n);
                waveOut.Play();
                CurrHash = "WSD_" + wsdNumber;
                Stopped  = false;
                Paused   = false;
            } catch { }
        }
コード例 #5
0
        /// <summary>
        /// Play a stream entry.
        /// </summary>
        /// <param name="a">Sound archive.</param>
        /// <param name="streamNumber">Stream number to play.</param>
        public static void PlayStream(SoundArchive a, int streamNumber)
        {
            //Try playing.
            Stop();
            try {
                //Stream.
                CitraFileLoader.Stream s = (CitraFileLoader.Stream)SoundArchiveReader.ReadFile(File.ReadAllBytes(BasePath + "/" + a.Streams[streamNumber].File.ExternalFileName));
                if (s.Stm.info.channels.Count > 2)
                {
                    switch (s.Stm.info.streamSoundInfo.encoding)
                    {
                    case 0:
                        s.Stm.data.pcm8 = new sbyte[][] { s.Stm.data.pcm8[0], s.Stm.data.pcm8[1] };
                        break;

                    case 1:
                        s.Stm.data.pcm16 = new short[][] { s.Stm.data.pcm16[0], s.Stm.data.pcm16[1] };
                        break;

                    case 2:
                        s.Stm.data.dspAdpcm = new byte[][] { s.Stm.data.dspAdpcm[0], s.Stm.data.dspAdpcm[1] };
                        break;
                    }
                }
                for (int i = 2; i < s.Stm.info.channels.Count; i++)
                {
                    s.Stm.info.channels.RemoveAt(i);
                }
                var m = new MemoryStream(s.Riff.ToBytes());
                var n = new WaveFileReader(m);
                waveOut.Initialize(n);
                waveOut.Play();
                CurrHash = "STM_" + streamNumber;
                Stopped  = false;
                Paused   = false;
            } catch { }
        }
コード例 #6
0
ファイル: FileWizard.cs プロジェクト: nnn1590/Citric-Composer
        public static SoundFile <ISoundFile> GetInfo(SoundArchive a, SoundArchive.NewFileEntryType type, int lastEntry, string filePath)
        {
            //File wizard.
            FileWizard w = new FileWizard();

            w.type = type;

            //Add existing files.
            foreach (var f in a.Files)
            {
                w.existingFiles.Items.Add(f.FileName + "." + f.FileExtension);
            }

            //Prepare info.
            w.referenceFileExternally.Enabled = false;
            w.referenceFileExternally.Checked = type == SoundArchive.NewFileEntryType.Stream;
            w.blankFile.Enabled       = type != SoundArchive.NewFileEntryType.Stream && type != SoundArchive.NewFileEntryType.Prefetch;
            w.useExistingFile.Checked = true;
            w.useExistingFile.Enabled = w.newFile.Checked = a.Files.Count == 0;
            w.useExistingFile.Enabled = !w.useExistingFile.Enabled;
            w.okButton.Enabled        = false;

            //Stream specifics.
            if (type == SoundArchive.NewFileEntryType.Stream)
            {
                w.blankFile.Enabled = false;
            }

            //Show.
            w.ShowDialog();

            //Return data.
            if (w.cancel)
            {
                return(new SoundFile <ISoundFile>()
                {
                    FileId = -1
                });
            }
            else
            {
                //Get versions.
                byte maj = 1;
                byte min = 0;
                byte rev = 0;

                //Use existing file.
                if (w.useExistingFile.Checked)
                {
                    return(new SoundFile <ISoundFile>()
                    {
                        Reference = a.Files[w.existingFiles.SelectedIndex]
                    });
                }

                //Use new file.
                else if (w.newFile.Checked)
                {
                    if (w.referenceFileExternally.Checked)
                    {
                        return(new SoundFile <ISoundFile>()
                        {
                            Reference = a.AddNewFile(type, lastEntry, null, false, GetRelativePath(w.newFilePath.Text, Path.GetDirectoryName(filePath)))
                        });
                    }
                    else
                    {
                        return(new SoundFile <ISoundFile>()
                        {
                            Reference = a.AddNewFile(type, lastEntry, SoundArchiveReader.ReadFile(File.ReadAllBytes(w.newFilePath.Text)))
                        });
                    }
                }

                //Blank file.
                else if (w.blankFile.Checked)
                {
                    ISoundFile f = null;
                    switch (type)
                    {
                    case SoundArchive.NewFileEntryType.Bank:
                        foreach (var fi in a.Files)
                        {
                            if (fi != null)
                            {
                                if (fi.File != null)
                                {
                                    var z = fi.File as SoundBank;
                                    if (z != null)
                                    {
                                        maj = z.Version.Major;
                                        min = z.Version.Minor;
                                        rev = z.Version.Revision;
                                        break;
                                    }
                                }
                            }
                        }
                        f = new SoundBank()
                        {
                            Version = new FileWriter.Version(maj, min, rev)
                        };
                        break;

                    case SoundArchive.NewFileEntryType.Group:
                        foreach (var fi in a.Files)
                        {
                            if (fi != null)
                            {
                                if (fi.File != null)
                                {
                                    var z = fi.File as Group;
                                    if (z != null)
                                    {
                                        maj = z.Version.Major;
                                        min = z.Version.Minor;
                                        rev = z.Version.Revision;
                                        break;
                                    }
                                }
                            }
                        }
                        f = new Group()
                        {
                            Version = new FileWriter.Version(maj, min, rev)
                        };
                        break;

                    case SoundArchive.NewFileEntryType.Sequence:
                        foreach (var fi in a.Files)
                        {
                            if (fi != null)
                            {
                                if (fi.File != null)
                                {
                                    var z = fi.File as SoundSequence;
                                    if (z != null)
                                    {
                                        maj = z.Version.Major;
                                        min = z.Version.Minor;
                                        rev = z.Version.Revision;
                                        break;
                                    }
                                }
                            }
                        }
                        f = new SoundSequence()
                        {
                            Version = new FileWriter.Version(maj, min, rev)
                        };
                        break;

                    case SoundArchive.NewFileEntryType.WaveArchive:
                        foreach (var fi in a.Files)
                        {
                            if (fi != null)
                            {
                                if (fi.File != null)
                                {
                                    var z = fi.File as SoundWaveArchive;
                                    if (z != null)
                                    {
                                        maj = z.Version.Major;
                                        min = z.Version.Minor;
                                        rev = z.Version.Revision;
                                        break;
                                    }
                                }
                            }
                        }
                        f = new SoundWaveArchive()
                        {
                            Version = new FileWriter.Version(maj, min, rev)
                        };
                        break;

                    case SoundArchive.NewFileEntryType.WaveSoundData:
                        foreach (var fi in a.Files)
                        {
                            if (fi != null)
                            {
                                if (fi.File != null)
                                {
                                    var z = fi.File as WaveSoundData;
                                    if (z != null)
                                    {
                                        maj = z.Version.Major;
                                        min = z.Version.Minor;
                                        rev = z.Version.Revision;
                                        break;
                                    }
                                }
                            }
                        }
                        f = new WaveSoundData()
                        {
                            Version = new FileWriter.Version(maj, min, rev)
                        };
                        break;
                    }
                    return(new SoundFile <ISoundFile>()
                    {
                        Reference = a.AddNewFile(type, lastEntry, f)
                    });
                }

                //Null file.
                else
                {
                    return(new SoundFile <ISoundFile>()
                    {
                        FileId = -2
                    });
                }
            }
        }
コード例 #7
0
ファイル: Bank.cs プロジェクト: cruuud/NitroStudio2
        /// <summary>
        /// Convert the bank to downloadable sounds.
        /// </summary>
        /// <param name="a">The sound archive.</param>
        /// <param name="b">The bank info.</param>
        /// <returns>The bank as DLS.</returns>
        public DownloadableSounds ToDLS(SoundArchive a, BankInfo b)
        {
            //New DLS.
            DownloadableSounds d = new DownloadableSounds();

            //Wave map.
            Dictionary <uint, RiffWave>   waveMap  = new Dictionary <uint, RiffWave>();
            Dictionary <ushort, RiffWave> psgMap   = new Dictionary <ushort, RiffWave>();
            Dictionary <ushort, RiffWave> noiseMap = new Dictionary <ushort, RiffWave>();

            d.Waves.Add(new RiffWave("Hardware/Null.wav"));

            //Add each instrument.
            foreach (var inst in Instruments)
            {
                //New instrument.
                GotaSoundBank.DLS.Instrument im = new GotaSoundBank.DLS.Instrument();
                im.BankId       = (uint)(inst.Index / 128);
                im.InstrumentId = (uint)(inst.Index % 128);
                im.Name         = "Instrument " + im.InstrumentId;

                //Add regions.
                byte lastNote = inst as DrumSetInstrument != null ? (inst as DrumSetInstrument).Min : (byte)0;
                foreach (var n in inst.NoteInfo)
                {
                    //New region.
                    Region r = new Region();

                    //Set note info.
                    r.VelocityLow    = 0;
                    r.VelocityHigh   = 127;
                    r.NoteLow        = lastNote;
                    r.NoteHigh       = (inst as DirectInstrument != null) ? (byte)127 : (byte)n.Key;
                    lastNote         = (byte)(n.Key + 1);
                    r.ChannelFlags   = 1;
                    r.DoublePlayback = true;
                    r.Layer          = 1;
                    r.NoTruncation   = true;
                    r.RootNote       = (byte)n.BaseNote;

                    //Wave data.
                    int wavInd = 0;
                    switch (n.InstrumentType)
                    {
                    case InstrumentType.PCM:
                        uint key = 0xFFFFFFFF;
                        try {
                            var p = b.WaveArchives[n.WarId].File.Waves[n.WaveId];
                            key = (uint)(b.WaveArchives[n.WarId].Index << 16) | n.WaveId;
                        } catch { }
                        if (key != 0xFFFFFFFF)
                        {
                            if (!waveMap.ContainsKey(key))
                            {
                                RiffWave pcm = new RiffWave();
                                pcm.FromOtherStreamFile(b.WaveArchives[n.WarId].File.Waves[n.WaveId]);
                                waveMap.Add(key, pcm);
                                d.Waves.Add(pcm);
                            }
                            wavInd = d.Waves.IndexOf(waveMap[key]);
                        }
                        break;

                    case InstrumentType.PSG:
                        if (!psgMap.ContainsKey(n.WaveId))
                        {
                            RiffWave psg = new RiffWave("Hardware/DutyCycle" + (n.WaveId + 1) + ".wav");
                            psgMap.Add(n.WaveId, psg);
                            d.Waves.Add(psg);
                        }
                        wavInd = d.Waves.IndexOf(psgMap[n.WaveId]);
                        break;

                    case InstrumentType.Noise:
                        if (!noiseMap.ContainsKey(0))
                        {
                            RiffWave noise = new RiffWave("Hardware/WhiteNoise.wav");
                            noiseMap.Add(0, noise);
                            d.Waves.Add(noise);
                            wavInd = d.Waves.IndexOf(noise);
                        }
                        else
                        {
                            wavInd = d.Waves.IndexOf(noiseMap[0]);
                        }
                        break;
                    }

                    //Set wave data.
                    r.WaveId = (uint)wavInd;
                    r.Loops  = d.Waves[wavInd].Loops;
                    if (r.Loops)
                    {
                        r.LoopStart  = d.Waves[wavInd].LoopStart;
                        r.LoopLength = d.Waves[wavInd].LoopEnd - d.Waves[wavInd].LoopStart;
                        if (r.LoopLength < 0)
                        {
                            r.LoopLength = 0;
                        }
                    }

                    //Articulator.
                    Articulator ar = new Articulator();
                    ar.Connections.Add(new Connection()
                    {
                        DestinationConnection = DestinationConnection.EG1AttackTime, Scale = n.Attack >= 127 ? int.MinValue : MillisecondsToTimecents(AttackTable[n.Attack]) * 65536
                    });
                    ar.Connections.Add(new Connection()
                    {
                        DestinationConnection = DestinationConnection.EG1DecayTime, Scale = n.Decay >= 127 ? int.MinValue : MillisecondsToTimecents(MaxReleaseTimes[n.Decay]) * 65536
                    });
                    ar.Connections.Add(new Connection()
                    {
                        DestinationConnection = DestinationConnection.EG1SustainLevel, Scale = (int)Math.Round(Sustain2Fraction(n.Sustain) * 1000, MidpointRounding.AwayFromZero) * 65536
                    });
                    ar.Connections.Add(new Connection()
                    {
                        DestinationConnection = DestinationConnection.EG1ReleaseTime, Scale = n.Release >= 127 ? int.MinValue : MillisecondsToTimecents(MaxReleaseTimes[n.Release]) * 65536
                    });
                    ar.Connections.Add(new Connection()
                    {
                        DestinationConnection = DestinationConnection.Pan, Scale = GetPan(n.Pan) * 65536
                    });
                    r.Articulators.Add(ar);

                    //Add region.
                    im.Regions.Add(r);
                }

                //Add the instrument.
                d.Instruments.Add(im);
            }

            //Return the DLS.
            return(d);
        }
コード例 #8
0
ファイル: Bank.cs プロジェクト: cruuud/NitroStudio2
 /// <summary>
 /// Convert the SBNK into a sound font.
 /// </summary>
 /// <param name="a">The sound archive.</param>
 /// <param name="b">The bank info.</param>
 /// <returns>This as a soundfont.</returns>
 public SoundFont ToSoundFont(SoundArchive a, BankInfo b)
 {
     //Laziness.
     return(new SoundFont(ToDLS(a, b)));
 }
コード例 #9
0
        /// <summary>
        /// Write an FSST file.
        /// </summary>
        /// <param name="folderPath">Directory to write FSST.</param>
        /// <param name="projectName">Name of the project.</param>
        /// <param name="a">Sound archive.</param>
        /// <param name="type">Export type.</param>
        public static void WriteFSST(string folderPath, string projectName, SoundArchive a, ExportType type)
        {
            using (FileStream fileStream = new FileStream(folderPath + "/" + projectName + "." + (type == ExportType.CTR ? "c" : "f") + "sst", FileMode.Create))
                using (StreamWriter sw = new StreamWriter(fileStream))
                    using (XmlTextWriter x = new XmlTextWriter(sw)) {
                        x.Formatting  = Formatting.Indented;
                        x.Indentation = 2;

                        x.WriteStartDocument();
                        x.WriteStartElement("SoundSet");
                        x.WriteAttributeString(new XAttribute(XNamespace.Xmlns + "xsi", "h").ToString().Trim("=\"h\"".ToCharArray()), "http://www.w3.org/2001/XMLSchema-instance");
                        x.WriteAttributeString(new XAttribute(XNamespace.Xmlns + "xsd", "h").ToString().Trim("=\"h\"".ToCharArray()), "http://www.w3.org/2001/XMLSchema");

                        //Get version.
                        string version = "1.";
                        switch (type)
                        {
                        case ExportType.Cafe:
                            version += "3";
                            break;

                        case ExportType.CTR:
                            version += "1";
                            break;

                        case ExportType.NX:
                            version += "0";
                            break;
                        }
                        version += ".0.0";

                        x.WriteAttributeString("Version", version);

                        //Get platform.
                        string platform = "Any";
                        switch (type)
                        {
                        case ExportType.Cafe:
                            platform = "Cafe";
                            break;

                        case ExportType.CTR:
                            platform = "Ctr";
                            break;
                        }

                        x.WriteAttributeString("Platform", platform);
                        x.WriteAttributeString(new XAttribute(XNamespace.Xmlns + "h", "h").ToString().Trim(":=\"hh\"".ToCharArray()), "NintendoWare.SoundFoundation.FileFormats.NintendoWare");

                        //Write head with title.
                        x.WriteStartElement("Head");
                        x.WriteElementString("Title", projectName + "SoundSet");
                        x.WriteEndElement(); //Head.

                        //Body.
                        x.WriteStartElement("Body");

                        //Sound set.
                        x.WriteStartElement("SoundSet");
                        x.WriteStartElement("Items");


                        //Stream sounds.
                        #region StreamSounds

                        /*
                         * //Header.
                         * x.WriteStartElement("SoundSetItemFolder");
                         * x.WriteAttributeString("Name", "@StreamSounds");
                         * x.WriteStartElement("Parameters");
                         * x.WriteStartElement("Comment");
                         * x.WriteEndElement();
                         * x.WriteStartElement("Comment1");
                         * x.WriteEndElement();
                         * x.WriteStartElement("Comment2");
                         * x.WriteEndElement();
                         * x.WriteStartElement("Comment3");
                         * x.WriteEndElement();
                         * x.WriteStartElement("Comment4");
                         * x.WriteEndElement();
                         * x.WriteStartElement("Comment5");
                         * x.WriteEndElement();
                         * x.WriteStartElement("Comment6");
                         * x.WriteEndElement();
                         * x.WriteStartElement("Comment7");
                         * x.WriteEndElement();
                         * x.WriteStartElement("Comment8");
                         * x.WriteEndElement();
                         * x.WriteStartElement("Comment9");
                         * x.WriteEndElement();
                         * x.WriteElementString("ColorIndex", "0");
                         * x.WriteElementString("IsEnabled", "True");
                         * x.WriteEndElement(); //Parameters.
                         * x.WriteStartElement("Items");
                         *
                         *
                         * //New stream.
                         * int streamNumber = 0;
                         * foreach (var s in a.Streams) {
                         *
                         *  //Get info.
                         *  string sName = (s.Name == null) ?
                         *
                         *  //Write player.
                         *  x.WriteStartElement("StreamSound");
                         *  x.WriteAttributeString("Name", sName);
                         *
                         *  x.WriteStartElement("Parameters");
                         *  x.WriteStartElement("Comment");
                         *  x.WriteEndElement();
                         *  x.WriteStartElement("Comment1");
                         *  x.WriteEndElement();
                         *  x.WriteStartElement("Comment2");
                         *  x.WriteEndElement();
                         *  x.WriteStartElement("Comment3");
                         *  x.WriteEndElement();
                         *  x.WriteStartElement("Comment4");
                         *  x.WriteEndElement();
                         *  x.WriteStartElement("Comment5");
                         *  x.WriteEndElement();
                         *  x.WriteStartElement("Comment6");
                         *  x.WriteEndElement();
                         *  x.WriteStartElement("Comment7");
                         *  x.WriteEndElement();
                         *  x.WriteStartElement("Comment8");
                         *  x.WriteEndElement();
                         *  x.WriteStartElement("Comment9");
                         *  x.WriteEndElement();
                         *  x.WriteElementString("ColorIndex", "0");
                         *  x.WriteElementString("IsEnabled", "True");
                         *
                         *  x.WriteElementString("RemoteFilter", "" + s.remoteFilter);
                         *  x.WriteElementString("Volume", "" + s.volume);
                         *
                         *  //TODO.
                         *  int priority = 64;
                         *  int actorNum = 0;
                         *  int panCurve = 0;
                         *  int userParam0 = 0; //Last bit (31).
                         *  int userParam1 = 0;
                         *  int userParam2 = 0;
                         *  int userParam3 = 0; //First bit (28).
                         *
                         *  //Get 3d info.
                         *  b_sar.InfoBlock.soundInfo.sound3dInfo d3 = new b_sar.InfoBlock.soundInfo.sound3dInfo()
                         *  {
                         *      flagBoxes = 0xF,
                         *      dimensionalAttenuation = .5f,
                         *      attenuationCurveType = 1,
                         *      dopplerFactor = 0,
                         *      padding = 0,
                         *      optionParameter = new FlagParameters(new Dictionary<int, uint>())
                         *  };
                         *
                         *  if (s.sound3d != null) {
                         *      d3 = s.sound3d;
                         *  }
                         *
                         *  string dCurve = d3.attenuationCurveType == 1 ? "Log" : "Linear";
                         *  bool dVol = BitHelperUInt.IsBitSet(d3.flagBoxes, 0);
                         *  bool dPri = BitHelperUInt.IsBitSet(d3.flagBoxes, 1);
                         *  bool dPan = BitHelperUInt.IsBitSet(d3.flagBoxes, 2);
                         *  bool dSpan = BitHelperUInt.IsBitSet(d3.flagBoxes, 3);
                         *  bool dFil = BitHelperUInt.IsBitSet(d3.flagBoxes, 4);
                         *
                         *  x.WriteElementString("PlayerPriority", "" + priority);
                         *  x.WriteStartElement("PlayerReference");
                         *  x.WriteAttributeString("Target", b.GetItemName(SDKSoundType.Player, (int)s.playerNumber.index));
                         *  x.WriteEndElement();
                         *  x.WriteElementString("ActorPlayer", "" + actorNum);
                         *  x.WriteElementString("UserParameter", "" + userParam0);
                         *  x.WriteElementString("UserParameter1", "" + userParam1);
                         *  x.WriteElementString("UserParameter2", "" + userParam2);
                         *  x.WriteElementString("UserParameter3", "" + userParam3);
                         *
                         *  x.WriteStartElement("Sound3D");
                         *  x.WriteStartElement("Parameters");
                         *
                         *  x.WriteElementString("DecayCurve3D", dCurve);
                         *  x.WriteElementString("DecayRatio3D", "" + d3.dimensionalAttenuation);
                         *  x.WriteElementString("DopplerFactor3D", "" + d3.dopplerFactor);
                         *  x.WriteElementString("Enable3DVolume", "" + dVol);
                         *  x.WriteElementString("Enable3DPan", "" + dPan);
                         *  x.WriteElementString("Enable3DSurroundPan", "" + dSpan);
                         *  x.WriteElementString("Enable3DPriority", "" + dPri);
                         *  x.WriteElementString("Enable3DFilter", "" + dFil);
                         *
                         *  x.WriteEndElement();
                         *  x.WriteEndElement();
                         *
                         *  x.WriteEndElement(); //Parameters.
                         *  x.WriteEndElement(); //Player
                         *
                         *  streamNumber++;
                         *
                         * }
                         *
                         * //Footer.
                         * x.WriteEndElement(); //Items.
                         * x.WriteEndElement(); //Sound set item folder.
                         */
                        #endregion

                        //Wave sound sets. TODO.
                        #region WaveSoundSets

                        //Header.
                        x.WriteStartElement("SoundSetItemFolder");
                        x.WriteAttributeString("Name", "@WaveSoundSets");
                        x.WriteStartElement("Parameters");
                        x.WriteStartElement("Comment");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment1");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment2");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment3");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment4");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment5");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment6");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment7");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment8");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment9");
                        x.WriteEndElement();
                        x.WriteElementString("ColorIndex", "0");
                        x.WriteElementString("IsEnabled", "True");
                        x.WriteEndElement(); //Parameters.
                        x.WriteStartElement("Items");

                        //Add items here.

                        //Footer.
                        x.WriteEndElement(); //Items.
                        x.WriteEndElement(); //Sound set item folder.

                        #endregion

                        //Sequence sounds. TODO.
                        #region SequenceSounds

                        //Header.
                        x.WriteStartElement("SoundSetItemFolder");
                        x.WriteAttributeString("Name", "@SequenceSounds");
                        x.WriteStartElement("Parameters");
                        x.WriteStartElement("Comment");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment1");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment2");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment3");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment4");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment5");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment6");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment7");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment8");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment9");
                        x.WriteEndElement();
                        x.WriteElementString("ColorIndex", "0");
                        x.WriteElementString("IsEnabled", "True");
                        x.WriteEndElement(); //Parameters.
                        x.WriteStartElement("Items");

                        //Add items here.

                        //Footer.
                        x.WriteEndElement(); //Items.
                        x.WriteEndElement(); //Sound set item folder.

                        #endregion

                        //Sequence sound sets. TODO.
                        #region SequenceSoundSets

                        //Header.
                        x.WriteStartElement("SoundSetItemFolder");
                        x.WriteAttributeString("Name", "@SequenceSoundSets");
                        x.WriteStartElement("Parameters");
                        x.WriteStartElement("Comment");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment1");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment2");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment3");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment4");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment5");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment6");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment7");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment8");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment9");
                        x.WriteEndElement();
                        x.WriteElementString("ColorIndex", "0");
                        x.WriteElementString("IsEnabled", "True");
                        x.WriteEndElement(); //Parameters.
                        x.WriteStartElement("Items");

                        //Add items here.

                        //Footer.
                        x.WriteEndElement(); //Items.
                        x.WriteEndElement(); //Sound set item folder.

                        #endregion

                        //Sound set banks. WARC NEEDS ATTENTION. TODO.
                        #region SoundSetBanks

                        //Header.
                        x.WriteStartElement("SoundSetItemFolder");
                        x.WriteAttributeString("Name", "@SoundSetBanks");
                        x.WriteStartElement("Parameters");
                        x.WriteStartElement("Comment");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment1");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment2");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment3");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment4");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment5");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment6");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment7");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment8");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment9");
                        x.WriteEndElement();
                        x.WriteElementString("ColorIndex", "0");
                        x.WriteElementString("IsEnabled", "True");
                        x.WriteEndElement(); //Parameters.
                        x.WriteStartElement("Items");

                        //New bank.
                        int bankNumber = 0;
                        foreach (var bnk in a.Banks)
                        {
                            //Get info.
                            string bName = "BANK_" + bankNumber.ToString("D4");
                            if (bnk.Name != null)
                            {
                                bName = bnk.Name;
                            }

                            //Write player.
                            x.WriteStartElement("SoundSetBank");
                            x.WriteAttributeString("Name", bName);

                            x.WriteStartElement("Parameters");
                            x.WriteStartElement("Comment");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment1");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment2");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment3");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment4");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment5");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment6");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment7");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment8");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment9");
                            x.WriteEndElement();
                            x.WriteElementString("ColorIndex", "0");
                            x.WriteElementString("IsEnabled", "True");

                            x.WriteElementString("FilePath", "BANK/" + bName + "." + (type == ExportType.CTR ? "c" : "f") + "bnk");
                            x.WriteStartElement("WaveArchiveReference");
                            x.WriteAttributeString("Target", "(AutoShared)");
                            x.WriteEndElement();

                            x.WriteEndElement(); //Parameters.
                            x.WriteEndElement(); //Bank.

                            bankNumber++;
                        }

                        //Footer.
                        x.WriteEndElement(); //Items.
                        x.WriteEndElement(); //Sound set item folder.

                        #endregion

                        //Wave archives. TODO.
                        #region WaveArchives

                        //Header.
                        x.WriteStartElement("SoundSetItemFolder");
                        x.WriteAttributeString("Name", "@WaveArchives");
                        x.WriteStartElement("Parameters");
                        x.WriteStartElement("Comment");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment1");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment2");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment3");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment4");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment5");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment6");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment7");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment8");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment9");
                        x.WriteEndElement();
                        x.WriteElementString("ColorIndex", "0");
                        x.WriteElementString("IsEnabled", "True");
                        x.WriteEndElement(); //Parameters.
                        x.WriteStartElement("Items");

                        //New war.
                        int warNumber = 0;
                        foreach (var w in a.WaveArchives)
                        {
                            //Get info.
                            string wName = "WARC_" + warNumber.ToString("D4");
                            if (w.Name != null)
                            {
                                wName = w.Name;
                            }

                            //Write war.
                            x.WriteStartElement("WaveArchive");
                            x.WriteAttributeString("Name", wName);

                            x.WriteStartElement("Parameters");
                            x.WriteStartElement("Comment");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment1");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment2");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment3");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment4");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment5");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment6");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment7");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment8");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment9");
                            x.WriteEndElement();
                            x.WriteElementString("ColorIndex", "0");
                            x.WriteElementString("IsEnabled", "True");

                            x.WriteElementString("WaveArchiveLoadType", w.LoadIndividually ? "Individual" : "Whole");

                            x.WriteEndElement(); //Parameters.
                            x.WriteEndElement(); //War.

                            warNumber++;
                        }

                        //Footer.
                        x.WriteEndElement(); //Items.
                        x.WriteEndElement(); //Sound set item folder.

                        #endregion

                        //Groups. TODO.
                        #region Groups

                        //Header.
                        x.WriteStartElement("SoundSetItemFolder");
                        x.WriteAttributeString("Name", "@Groups");
                        x.WriteStartElement("Parameters");
                        x.WriteStartElement("Comment");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment1");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment2");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment3");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment4");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment5");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment6");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment7");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment8");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment9");
                        x.WriteEndElement();
                        x.WriteElementString("ColorIndex", "0");
                        x.WriteElementString("IsEnabled", "True");
                        x.WriteEndElement(); //Parameters.
                        x.WriteStartElement("Items");

                        //Add items here.
                        int groupNumber = 0;
                        foreach (var g in a.Groups)
                        {
                            //Get info.
                            string name = "GROUP_" + groupNumber.ToString("D4");
                            if (g.Name != null)
                            {
                                name = g.Name;
                            }

                            //Write player.
                            x.WriteStartElement("Group");
                            x.WriteAttributeString("Name", name);

                            x.WriteStartElement("Parameters");
                            x.WriteStartElement("Comment");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment1");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment2");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment3");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment4");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment5");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment6");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment7");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment8");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment9");
                            x.WriteEndElement();
                            x.WriteElementString("ColorIndex", "0");
                            x.WriteElementString("IsEnabled", "True");

                            x.WriteElementString("PlayerSoundLimit", g.Name + "");

                            x.WriteEndElement(); //Parameters.
                            x.WriteEndElement(); //Player

                            groupNumber++;
                        }

                        //Footer.
                        x.WriteEndElement(); //Items.
                        x.WriteEndElement(); //Sound set item folder.

                        #endregion

                        //Players.
                        #region Players

                        //Header.
                        x.WriteStartElement("SoundSetItemFolder");
                        x.WriteAttributeString("Name", "@Players");
                        x.WriteStartElement("Parameters");
                        x.WriteStartElement("Comment");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment1");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment2");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment3");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment4");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment5");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment6");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment7");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment8");
                        x.WriteEndElement();
                        x.WriteStartElement("Comment9");
                        x.WriteEndElement();
                        x.WriteElementString("ColorIndex", "0");
                        x.WriteElementString("IsEnabled", "True");
                        x.WriteEndElement(); //Parameters.
                        x.WriteStartElement("Items");

                        //New player.
                        int playerNumber = 0;
                        foreach (var p in a.Players)
                        {
                            //Get info.
                            string pName      = "PLAYER_" + playerNumber.ToString("D4");
                            uint   pSoundHeap = 0;
                            if (p.Name != null)
                            {
                                pName = p.Name;
                            }

                            //Write player.
                            x.WriteStartElement("Player");
                            x.WriteAttributeString("Name", pName);

                            x.WriteStartElement("Parameters");
                            x.WriteStartElement("Comment");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment1");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment2");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment3");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment4");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment5");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment6");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment7");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment8");
                            x.WriteEndElement();
                            x.WriteStartElement("Comment9");
                            x.WriteEndElement();
                            x.WriteElementString("ColorIndex", "0");
                            x.WriteElementString("IsEnabled", "True");

                            x.WriteElementString("PlayerSoundLimit", p.SoundLimit + "");
                            x.WriteElementString("PlayerHeapSize", pSoundHeap + "");

                            x.WriteEndElement(); //Parameters.
                            x.WriteEndElement(); //Player

                            playerNumber++;
                        }

                        //Footer.
                        x.WriteEndElement(); //Items.
                        x.WriteEndElement(); //Sound set item folder.

                        #endregion

                        //Close elements.
                        x.WriteEndElement(); //Items.
                        x.WriteEndElement(); //Sound set.

                        x.WriteEndElement(); //Body.

                        x.WriteEndElement(); //Sound set.
                        x.WriteEndDocument();
                        x.Flush();
                    }
        }
コード例 #10
0
        /// <summary>
        /// Write an FSPJ file.
        /// </summary>
        /// <param name="folderPath">Directory to write FSPJ.</param>
        /// <param name="projectName">Name of the project.</param>
        /// <param name="a">Sound archive.</param>
        /// <param name="type">Export type.</param>
        public static void WriteFSPJ(string folderPath, string projectName, SoundArchive a, ExportType type)
        {
            using (FileStream fileStream = new FileStream(folderPath + "/" + projectName + "." + (type == ExportType.CTR ? "c" : "f") + "spj", FileMode.Create))
                using (StreamWriter sw = new StreamWriter(fileStream))
                    using (XmlTextWriter x = new XmlTextWriter(sw)) {
                        x.Formatting  = Formatting.Indented;
                        x.Indentation = 2;

                        x.WriteStartDocument();
                        x.WriteStartElement("SoundProject");
                        x.WriteAttributeString(new XAttribute(XNamespace.Xmlns + "xsi", "h").ToString().Trim("=\"h\"".ToCharArray()), "http://www.w3.org/2001/XMLSchema-instance");
                        x.WriteAttributeString(new XAttribute(XNamespace.Xmlns + "xsd", "h").ToString().Trim("=\"h\"".ToCharArray()), "http://www.w3.org/2001/XMLSchema");

                        //Get version.
                        string version = "1.";
                        switch (type)
                        {
                        case ExportType.Cafe:
                            version += "4";
                            break;

                        case ExportType.CTR:
                            version += "6";
                            break;

                        case ExportType.NX:
                            version += "1";
                            break;
                        }
                        version += ".0.0";

                        x.WriteAttributeString("Version", version);

                        //Get platform.
                        string platform = "Any";
                        switch (type)
                        {
                        case ExportType.Cafe:
                            platform = "Cafe";
                            break;

                        case ExportType.CTR:
                            platform = "Ctr";
                            break;
                        }

                        x.WriteAttributeString("Platform", platform);
                        x.WriteAttributeString(new XAttribute(XNamespace.Xmlns + "h", "h").ToString().Trim(":=\"hh\"".ToCharArray()), "NintendoWare.SoundFoundation.FileFormats.NintendoWare");

                        //Write head with title.
                        x.WriteStartElement("Head");
                        x.WriteElementString("Title", projectName + "SoundProject");
                        x.WriteEndElement(); //Head.

                        //Body.
                        x.WriteStartElement("Body");

                        //Sound project.
                        x.WriteStartElement("SoundProject");

                        //Project sound sets.
                        x.WriteStartElement("ProjectSoundSets");
                        x.WriteStartElement("ProjectSoundSet");
                        x.WriteAttributeString("Name", projectName);
                        x.WriteStartElement("Parameters");
                        x.WriteElementString("FilePath", projectName + "." + (type == ExportType.CTR ? "c" : "f") + "sst");
                        x.WriteEndElement(); //Parameters.
                        x.WriteEndElement(); //Project sound set.
                        x.WriteEndElement(); //Project sound sets.

                        //Sound archive player.
                        x.WriteStartElement("SoundArchivePlayer");
                        x.WriteStartElement("Parameters");
                        x.WriteElementString("SoundArchivePlayerSequenceSoundCount", "" + a.MaxSequences);
                        x.WriteElementString("SoundArchivePlayerSequenceTrackCount", "" + a.MaxSequenceTracks);
                        x.WriteElementString("SoundArchivePlayerStreamChannelCount", "" + a.MaxStreamChannels);
                        x.WriteElementString("SoundArchivePlayerStreamBufferTimes", "" + a.StreamBufferTimes);
                        x.WriteElementString("SoundArchivePlayerStreamSoundCount", "" + a.MaxStreamSounds);
                        x.WriteElementString("SoundArchivePlayerWaveSoundCount", "" + a.MaxWaveSounds);
                        x.WriteEndElement(); //Parameters.
                        x.WriteEndElement(); //Sound archive player.

                        //Convert.
                        x.WriteStartElement("Convert");
                        x.WriteStartElement("Parameters");

                        x.WriteElementString("DoWarnUnreferencedItems", "False");
                        x.WriteElementString("DoWarnDisableGroupItemTargets", "False");
                        if (type != ExportType.CTR)
                        {
                            x.WriteElementString("DoWarnPCBinariesForAACNotFound", "True");
                        }
                        x.WriteElementString("ExcludeStringTable", "False");
                        if (type != ExportType.CTR)
                        {
                            x.WriteElementString("DoOutputPCBinariesForAAC", "True");
                        }
                        x.WriteElementString("ExternalFileDirectoryPath", "stream");
                        x.WriteElementString("UserManagementFileOutputDirectoryPath", "userManagementFiles");
                        x.WriteElementString("IntermediateOutputDirectoryPath", "cache");
                        x.WriteElementString("InGameEditCacheOutputDirectoryPath", "editCache");
                        x.WriteElementString("IsPreConvertCommandsEnabled", "True");
                        x.WriteElementString("IsPostConvertCommandsEnabled", "True");
                        x.WriteElementString("KeepIntermediateTextSequence", "True");
                        x.WriteElementString("OutputLabel", "False");
                        x.WriteElementString("OutputDirectoryPath", "output");
                        x.WriteElementString("SmfTimebase", "96");

                        x.WriteStartElement("PreConvertCommands");
                        x.WriteEndElement();
                        x.WriteStartElement("PostConvertCommands");
                        x.WriteEndElement();
                        x.WriteEndElement(); //Parameters.
                        x.WriteEndElement(); //Convert.

                        //Item naming.
                        x.WriteStartElement("ItemNaming");
                        x.WriteStartElement("Parameters");

                        x.WriteElementString("BankNamePrefix", "BANK_");
                        x.WriteElementString("CaseChange", "ToUpper");
                        x.WriteElementString("GroupNamePrefix", "GROUP_");
                        x.WriteElementString("HasPrefix", "True");
                        x.WriteElementString("InstrumentNamePrefix", "INST_");
                        x.WriteElementString("InvalidCharChange", "ReplaceToUnderscore");
                        x.WriteElementString("PlayerNamePrefix", "PLAYER_");
                        x.WriteElementString("SequenceSoundNamePrefix", "SEQ_");
                        x.WriteElementString("SequenceSoundSetNamePrefix", "SEQSET_");
                        x.WriteElementString("StreamSoundNamePrefix", "STRM_");
                        x.WriteElementString("WaveArchiveNamePrefix", "WARC_");
                        x.WriteElementString("WaveSoundNamePrefix", "WSD_");
                        x.WriteElementString("WaveSoundSetNamePrefix", "WSDSET_");
                        x.WriteElementString("ItemPastePostfix", "_copy");
                        x.WriteElementString("EnabledNameDelimiter", "True");
                        x.WriteElementString("NameDelimiter", ".");

                        x.WriteEndElement(); //Parameters.
                        x.WriteEndElement(); //Item naming.

                        //Comment column text.
                        x.WriteStartElement("CommentColumnText");
                        x.WriteStartElement("Parameters");

                        x.WriteElementString("CommentColumnText", "Comments");
                        x.WriteElementString("Comment1ColumnText", "Comment 1");
                        x.WriteElementString("Comment2ColumnText", "Comment 2");
                        x.WriteElementString("Comment3ColumnText", "Comment 3");
                        x.WriteElementString("Comment4ColumnText", "Comment 4");
                        x.WriteElementString("Comment5ColumnText", "Comment 5");
                        x.WriteElementString("Comment6ColumnText", "Comment 6");
                        x.WriteElementString("Comment7ColumnText", "Comment 7");
                        x.WriteElementString("Comment8ColumnText", "Comment 8");
                        x.WriteElementString("Comment9ColumnText", "Comment 9");

                        x.WriteEndElement(); //Parameters.
                        x.WriteEndElement(); //Comment column text.

                        //Color comment.
                        x.WriteStartElement("ColorComment");
                        x.WriteStartElement("Parameters");

                        x.WriteStartElement("ColorComment0");
                        x.WriteEndElement();
                        x.WriteStartElement("ColorComment1");
                        x.WriteEndElement();
                        x.WriteStartElement("ColorComment2");
                        x.WriteEndElement();
                        x.WriteStartElement("ColorComment3");
                        x.WriteEndElement();
                        x.WriteStartElement("ColorComment4");
                        x.WriteEndElement();
                        x.WriteStartElement("ColorComment5");
                        x.WriteEndElement();
                        x.WriteStartElement("ColorComment6");
                        x.WriteEndElement();
                        x.WriteStartElement("ColorComment7");
                        x.WriteEndElement();
                        x.WriteStartElement("ColorComment8");
                        x.WriteEndElement();

                        x.WriteEndElement(); //Parameters.
                        x.WriteEndElement(); //Color comment.

                        //User commands.
                        x.WriteStartElement("UserCommands");

                        x.WriteStartElement("UserCommand");
                        x.WriteAttributeString("Name", "");
                        x.WriteAttributeString("Command", "");
                        x.WriteAttributeString("IconFilePath", "");
                        x.WriteEndElement();

                        x.WriteStartElement("UserCommand");
                        x.WriteAttributeString("Name", "");
                        x.WriteAttributeString("Command", "");
                        x.WriteAttributeString("IconFilePath", "");
                        x.WriteEndElement();

                        x.WriteStartElement("UserCommand");
                        x.WriteAttributeString("Name", "");
                        x.WriteAttributeString("Command", "");
                        x.WriteAttributeString("IconFilePath", "");
                        x.WriteEndElement();

                        x.WriteStartElement("UserCommand");
                        x.WriteAttributeString("Name", "");
                        x.WriteAttributeString("Command", "");
                        x.WriteAttributeString("IconFilePath", "");
                        x.WriteEndElement();

                        x.WriteStartElement("UserCommand");
                        x.WriteAttributeString("Name", "");
                        x.WriteAttributeString("Command", "");
                        x.WriteAttributeString("IconFilePath", "");
                        x.WriteEndElement();

                        x.WriteStartElement("UserCommand");
                        x.WriteAttributeString("Name", "");
                        x.WriteAttributeString("Command", "");
                        x.WriteAttributeString("IconFilePath", "");
                        x.WriteEndElement();

                        x.WriteStartElement("UserCommand");
                        x.WriteAttributeString("Name", "");
                        x.WriteAttributeString("Command", "");
                        x.WriteAttributeString("IconFilePath", "");
                        x.WriteEndElement();

                        x.WriteStartElement("UserCommand");
                        x.WriteAttributeString("Name", "");
                        x.WriteAttributeString("Command", "");
                        x.WriteAttributeString("IconFilePath", "");
                        x.WriteEndElement();

                        x.WriteEndElement(); //User commands.

                        x.WriteStartElement("SoundListOutputs");
                        x.WriteEndElement();

                        //User parameter settings.
                        x.WriteStartElement("UserParameterSettings");

                        x.WriteStartElement("UserParameterSetting");
                        x.WriteAttributeString("Enabled", "true");
                        x.WriteStartElement("UserParameterStructures");
                        x.WriteEndElement();
                        x.WriteEndElement();

                        x.WriteStartElement("UserParameterSetting");
                        x.WriteAttributeString("Enabled", "true");
                        x.WriteStartElement("UserParameterStructures");
                        x.WriteEndElement();
                        x.WriteEndElement();

                        x.WriteStartElement("UserParameterSetting");
                        x.WriteAttributeString("Enabled", "true");
                        x.WriteStartElement("UserParameterStructures");
                        x.WriteEndElement();
                        x.WriteEndElement();

                        x.WriteStartElement("UserParameterSetting");
                        x.WriteAttributeString("Enabled", "true");
                        x.WriteStartElement("UserParameterStructures");
                        x.WriteEndElement();
                        x.WriteEndElement();

                        x.WriteEndElement();

                        //Project setting.
                        x.WriteStartElement("ProjectSetting");
                        x.WriteStartElement("Parameters");
                        x.WriteStartElement("ProjectComment");
                        x.WriteEndElement();
                        x.WriteEndElement();
                        x.WriteEndElement();

                        //File event.
                        x.WriteStartElement("FileEvent");
                        x.WriteStartElement("Parameters");
                        x.WriteElementString("IsFileSavePreCommandEnabled", "False");
                        x.WriteElementString("IsFileSavePostCommandEnabled", "False");
                        x.WriteStartElement("FileSavePreCommandPath");
                        x.WriteEndElement();
                        x.WriteStartElement("FileSavePostCommandPath");
                        x.WriteEndElement();
                        x.WriteEndElement();
                        x.WriteEndElement();

                        //Snd edit.
                        x.WriteStartElement("SndEdit");
                        x.WriteStartElement("Parameters");
                        x.WriteElementString("SyncPort", type == ExportType.CTR ? "10" : "54086");
                        x.WriteElementString("SyncPort", type == ExportType.CTR ? "11" : "54087");
                        x.WriteElementString("SyncPort", type == ExportType.CTR ? "12" : "54088");
                        x.WriteEndElement();
                        x.WriteEndElement();


                        x.WriteEndElement(); //Sound project.

                        x.WriteEndElement(); //Body.

                        x.WriteEndElement(); //SoundProject.
                        x.WriteEndDocument();
                        x.Flush();
                    }
        }
コード例 #11
0
        /// <summary>
        /// From text.
        /// </summary>
        /// <param name="text">The text to parse.</param>
        /// <param name="a">Sound archive.</param>
        public void FromText(List <string> text, SoundArchive a)
        {
            //Success by default.
            WritingCommandSuccess = true;

            //Get platform.
            var p = Platform();

            //Reset labels.
            PublicLabels = new Dictionary <string, int>();
            OtherLabels  = new List <int>();
            Dictionary <string, int> privateLabels = new Dictionary <string, int>();
            List <int> labelLines = new List <int>();

            //Format text.
            List <string> t      = text.ToList();
            int           comNum = 0;

            for (int i = t.Count - 1; i >= 0; i--)
            {
                t[i] = t[i].Replace("\t", "").Replace("\r", "");
                try { t[i] = t[i].Split(';')[0]; } catch { }
                if (t[i].Replace(" ", "").Length == 0)
                {
                    t.RemoveAt(i); continue;
                }
                for (int j = 0; j < t[i].Length; j++)
                {
                    if (t[i][j].Equals(' '))
                    {
                        t[i] = t[i].Substring(j + 1);
                        j--;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            //Sequence id to label name.
            Dictionary <int, string> seqId2Label = new Dictionary <int, string>();

            //Get sequences.
            Sequences = new List <SequenceArchiveSequence>();
            int currSeqId = 0;

            for (int i = t.IndexOf("@SEQ_TABLE") + 1; i < t.IndexOf("@SEQ_DATA"); i++)
            {
                //New sequence.
                SequenceArchiveSequence s = new SequenceArchiveSequence();

                //Get sequence data.
                string[] seqData = t[i].Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "").Split(',');

                //Get sequence.
                string label       = seqData[0].Split(':')[1];
                string seqNameData = seqData[0].Split(':')[0];
                if (seqNameData.Contains("="))
                {
                    currSeqId = int.Parse(seqNameData.Split('=')[1]);
                    s.Name    = seqNameData.Split('=')[0];
                }
                else
                {
                    s.Name = seqNameData;
                }
                s.Index = currSeqId;
                seqId2Label.Add(currSeqId++, label);
                s.LabelName = label;

                //Bank.
                string bnk = seqData[1];
                if (ushort.TryParse(bnk, out _))
                {
                    s.ReadingBankId = ushort.Parse(bnk);
                    if (a != null)
                    {
                        s.Bank = a.Banks.Where(x => x.Index == s.ReadingBankId).FirstOrDefault();
                    }
                }
                else if (a != null)
                {
                    var bnkReal = a.Banks.Where(x => x.Name.Equals(bnk)).FirstOrDefault();
                    if (bnkReal == null)
                    {
                        throw new Exception("Bank " + bnk + " does not exist!");
                    }
                    s.ReadingBankId = (ushort)bnkReal.Index;
                    s.Bank          = bnkReal;
                }
                else
                {
                    throw new Exception("Can't use a name when there is no sound archive open!");
                }

                //Data.
                s.Volume          = byte.Parse(seqData[2]);
                s.ChannelPriority = byte.Parse(seqData[3]);
                s.PlayerPriority  = byte.Parse(seqData[4]);

                //Player
                string ply = seqData[5];
                if (ushort.TryParse(ply, out _))
                {
                    s.ReadingPlayerId = byte.Parse(ply);
                    if (a != null)
                    {
                        s.Player = a.Players.Where(x => x.Index == s.ReadingPlayerId).FirstOrDefault();
                    }
                }
                else if (a != null)
                {
                    var plyReal = a.Players.Where(x => x.Name.Equals(ply)).FirstOrDefault();
                    if (plyReal == null)
                    {
                        throw new Exception("Player " + ply + " does not exist!");
                    }
                    s.ReadingPlayerId = (byte)plyReal.Index;
                    s.Player          = plyReal;
                }
                else
                {
                    throw new Exception("Can't use a name when there is no sound archive open!");
                }

                //Add sequence.
                Sequences.Add(s);
            }

            //Fetch labels.
            int strt = t.IndexOf("@SEQ_DATA") + 1;

            for (int i = strt; i < t.Count; i++)
            {
                //If it's a label.
                if (t[i].EndsWith(":"))
                {
                    labelLines.Add(i);
                    string lbl = t[i].Replace(":", "");
                    if (!seqId2Label.ContainsValue(lbl))
                    {
                        privateLabels.Add(lbl, comNum);
                        OtherLabels.Add(comNum);
                    }
                    else
                    {
                        PublicLabels.Add(lbl, comNum);
                    }
                }
                else
                {
                    comNum++;
                }
            }

            //Get commands.
            Commands = new List <SequenceCommand>();
            for (int i = t.IndexOf("@SEQ_DATA") + 1; i < t.Count; i++)
            {
                if (labelLines.Contains(i))
                {
                    continue;
                }
                SequenceCommand seq = new SequenceCommand();
                try { seq.FromString(t[i], PublicLabels, privateLabels); } catch { WritingCommandSuccess = false; throw new Exception("Command " + i + ": \"" + t[i] + "\" is invalid."); }
                Commands.Add(seq);
            }

            //Fin.
            Commands.Add(new SequenceCommand()
            {
                CommandType = SequenceCommands.Fin
            });

            //Backup labels.
            var bakLabels = PublicLabels;

            PublicLabels = new Dictionary <string, int>();
            foreach (var seq in Sequences)
            {
                PublicLabels.Add(seq.Name, bakLabels[seq.LabelName]);
            }
        }
コード例 #12
0
        public static SoundInfo GetInfo(SoundInfo bak, SoundArchive a, string name)
        {
            //Sound editor.
            SoundEditor e = new SoundEditor();

            //Player grid.
            e.player.Items.Clear();
            foreach (var p in a.Players)
            {
                e.player.Items.Add(p.Name != null ? p.Name : "{ Unknown Player Name }");
            }

            //Other stuff.
            e.Text = name;
            e.frontBypass.Checked         = bak.IsFrontBypass;
            e.panCurve.SelectedIndex      = (int)bak.PanCurve;
            e.panMode.SelectedIndex       = (int)bak.PanMode;
            e.player.SelectedIndex        = a.Players.IndexOf(bak.Player);
            e.playerActorId.SelectedIndex = bak.PlayerActorId;
            e.playerPriority.Value        = bak.PlayerPriority;
            e.remoteFilter.Value          = bak.RemoteFilter;
            e.volume.Value     = bak.Volume;
            e.p1Enable.Checked = e.p1.Enabled = bak.UserParamsEnabled[0];
            e.p2Enable.Checked = e.p2.Enabled = bak.UserParamsEnabled[1];
            e.p3Enable.Checked = e.p3.Enabled = bak.UserParamsEnabled[2];
            e.p4Enable.Checked = e.p4.Enabled = bak.UserParamsEnabled[3];
            e.p1.Value         = bak.UserParamsEnabled[0] ? bak.UserParameter[0] : 0;
            e.p2.Value         = bak.UserParamsEnabled[1] ? bak.UserParameter[1] : 0;
            e.p3.Value         = bak.UserParamsEnabled[2] ? bak.UserParameter[2] : 0;
            e.p4.Value         = bak.UserParamsEnabled[3] ? bak.UserParameter[3] : 0;
            e.bak = bak;
            e.ShowDialog();
            if (e.ok)
            {
                return(new SoundInfo()
                {
                    File = bak.File,
                    IsFrontBypass = e.frontBypass.Checked,
                    Name = bak.Name,
                    PanCurve = (SoundInfo.EPanCurve)e.panCurve.SelectedIndex,
                    PanMode = (SoundInfo.EPanMode)e.panMode.SelectedIndex,
                    Player = a.Players[e.player.SelectedIndex],
                    PlayerActorId = (sbyte)e.playerActorId.SelectedIndex,
                    PlayerPriority = (sbyte)e.playerPriority.Value,
                    RemoteFilter = (sbyte)e.remoteFilter.Value,
                    Sound3dInfo = bak.Sound3dInfo,
                    Volume = (byte)e.volume.Value,
                    UserParamsEnabled = new bool[] { e.p1Enable.Checked, e.p2Enable.Checked, e.p3Enable.Checked, e.p4Enable.Checked },
                    UserParameter = new uint[]
                    {
                        (uint)(e.p1Enable.Checked ? e.p1.Value : 0),
                        (uint)(e.p2Enable.Checked ? e.p2.Value : 0),
                        (uint)(e.p3Enable.Checked ? e.p3.Value : 0),
                        (uint)(e.p4Enable.Checked ? e.p4.Value : 0)
                    }
                });
            }
            else
            {
                return(e.bak);
            }
        }
コード例 #13
0
        /// <summary>
        /// Write an instrument.
        /// </summary>
        /// <param name="bnk">The bank.</param>
        /// <param name="instrumentId">The instrument Id.</param>
        /// <param name="a">Sound archive.</param>
        /// <param name="war0">Wave archive 0.</param>
        /// <param name="war1">Wave archive 1.</param>
        /// <param name="war2">Wave archive 2.</param>
        /// <param name="war3">Wave archive 3.</param>
        public void WriteInstrument(Bank bnk, int instrumentId, SoundArchive a, ushort war0, ushort war1, ushort war2, ushort war3)
        {
            //Set the instrument.
            var repl = bnk.Instruments.Where(x => x.Index == instrumentId).FirstOrDefault();

            Inst.Index = instrumentId;

            //Sound archive check.
            if (a == null)
            {
                return;
            }

            //Get wave archives.
            WaveArchiveInfo[] wars = new WaveArchiveInfo[4];
            if (war0 != 0xFFFF)
            {
                wars[0] = a.WaveArchives.Where(x => x.Index == (int)war0).FirstOrDefault();
            }
            if (war1 != 0xFFFF)
            {
                wars[1] = a.WaveArchives.Where(x => x.Index == (int)war1).FirstOrDefault();
            }
            if (war2 != 0xFFFF)
            {
                wars[2] = a.WaveArchives.Where(x => x.Index == (int)war2).FirstOrDefault();
            }
            if (war3 != 0xFFFF)
            {
                wars[3] = a.WaveArchives.Where(x => x.Index == (int)war3).FirstOrDefault();
            }

            //Make sure there are linked wave archives.
            if (wars.Where(x => x != null).Count() < 1)
            {
                return;
            }

            //For each region in the instrument.
            foreach (var r in Inst.NoteInfo)
            {
                //PCM type.
                if (r.InstrumentType != InstrumentType.PCM)
                {
                    continue;
                }

                //Waves are not null.
                if (Waves == null)
                {
                    continue;
                }

                //Get entry.
                var e = Waves.Where(x => x.WarId == r.WarId && x.WaveId == r.WaveId).FirstOrDefault();
                if (e == null)
                {
                    continue;
                }

                //Wave is not null.
                if (e.Wave == null)
                {
                    continue;
                }

                //Get MD5SUM of wave.
                string md5 = e.Wave.Md5Sum;

                //Try and find matching wave.
                bool found = false;
                for (int i = 0; i < wars.Length; i++)
                {
                    if (wars[i] != null)
                    {
                        for (int j = 0; j < wars[i].File.Waves.Count; j++)
                        {
                            if (!found && wars[i].File.Waves[j].Md5Sum == md5)
                            {
                                r.WaveId = (ushort)j;
                                r.WarId  = (ushort)i;
                                found    = true;
                            }
                        }
                    }
                }

                //Not found.
                if (!found)
                {
                    RiffWave riff = new RiffWave();
                    riff.FromOtherStreamFile(e.Wave);
                    WaveMapper mapper = new WaveMapper(new List <RiffWave>()
                    {
                        riff
                    }, wars.Where(x => x != null).ToList(), true);
                    mapper.MinimizeBox = false;
                    mapper.ShowDialog();
                    if (mapper.WarMap == null)
                    {
                        return;
                    }
                    a.WaveArchives.Where(x => x.Index == mapper.WarMap[0]).FirstOrDefault().File.Waves.Add(e.Wave);
                    r.WaveId = (ushort)(a.WaveArchives.Where(x => x.Index == mapper.WarMap[0]).FirstOrDefault().File.Waves.Count() - 1);
                    r.WarId  = (ushort)wars.ToList().IndexOf(a.WaveArchives.Where(x => x.Index == mapper.WarMap[0]).FirstOrDefault());
                }
            }

            //Set instrument.
            bnk.Instruments[bnk.Instruments.IndexOf(repl)] = Inst;
        }