Пример #1
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            Sound  selectedFile = SearchFile();
            String fileout      = pluginHost.Get_TempFolder() + Path.DirectorySeparatorChar + Path.GetRandomFileName();

            OpenFileDialog o = new OpenFileDialog();

            o.CheckFileExists = true;
            o.AddExtension    = true;
            o.DefaultExt      = "wav";
            o.Filter          = "WAVE audio format (*.wav)|*.wav";
            if (o.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            String filein = o.FileName;

            sWAV wav = new sWAV();

            try { wav = WAV.Read(filein); }
            catch (Exception ex) { MessageBox.Show(ex.Message); return; }

            NewAudioOptions dialog = new NewAudioOptions(pluginHost, (selectedFile.type == FormatSound.SWAV ? true : false));

            switch (selectedFile.type)
            {
            case FormatSound.STRM:
                sSTRM oldStrm = STRM.Read(SaveFile());
                dialog.Compression = oldStrm.head.waveType;
                dialog.BlockSize   = (int)oldStrm.head.blockLen;
                dialog.Loop        = (oldStrm.head.loop != 0 ? true : false);
                dialog.LoopOffset  = (int)oldStrm.head.loopOffset;
                dialog.SampleRate  = (int)wav.wave.fmt.sampleRate;
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                sSTRM strm = STRM.ConvertToSTRM(wav, dialog.Compression);
                strm.head.loop       = (byte)(dialog.Loop ? 0x01 : 0x00);
                strm.head.loopOffset = (uint)dialog.LoopOffset;

                STRM.Write(strm, fileout);
                break;

            case FormatSound.SWAV:
                sSWAV oldSwav = SWAV.Read(SaveFile());
                dialog.Compression = oldSwav.data.info.nWaveType;
                dialog.Loop        = (oldSwav.data.info.bLoop != 0 ? true : false);
                dialog.LoopLength  = (int)oldSwav.data.info.nNonLoopLen;
                dialog.LoopOffset  = (int)oldSwav.data.info.nLoopOffset;
                dialog.SampleRate  = (int)wav.wave.fmt.sampleRate;
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                sSWAV swav = SWAV.ConvertToSWAV(wav, dialog.Compression, dialog.Volume);

                swav.data.info.bLoop       = (byte)(dialog.Loop ? 0x01 : 0x00);
                swav.data.info.nLoopOffset = (ushort)dialog.LoopOffset;
                swav.data.info.nNonLoopLen = (uint)dialog.LoopLength;

                SWAV.Write(swav, fileout);
                break;

            case FormatSound.SSEQ:
            case FormatSound.SSAR:
            case FormatSound.SBNK:
            case FormatSound.SWAR:
            default:
                break;
            }

            if (!File.Exists(fileout))
            {
                return;
            }
            ChangeFile((int)selectedFile.id, fileout);
        }
Пример #2
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            Sound selectedFile = SearchFile();
            String fileout = pluginHost.Get_TempFolder() + Path.DirectorySeparatorChar + Path.GetRandomFileName();

            OpenFileDialog o = new OpenFileDialog();
            o.CheckFileExists = true;
            o.AddExtension = true;
            o.DefaultExt = "wav";
            o.Filter = "WAVE audio format (*.wav)|*.wav";
            if (o.ShowDialog() != DialogResult.OK)
                return;
            String filein = o.FileName;

            sWAV wav = new sWAV();
            try { wav = WAV.Read(filein); }
            catch (Exception ex) { MessageBox.Show(ex.Message); return; }

            NewAudioOptions dialog = new NewAudioOptions(pluginHost, (selectedFile.type == FormatSound.SWAV ? true : false));

            switch (selectedFile.type)
            {
                case FormatSound.STRM:
                    sSTRM oldStrm = STRM.Read(SaveFile());
                    dialog.Compression = oldStrm.head.waveType;
                    dialog.BlockSize = (int)oldStrm.head.blockLen;
                    dialog.Loop = (oldStrm.head.loop != 0 ? true : false);
                    dialog.LoopOffset = (int)oldStrm.head.loopOffset;
                    dialog.SampleRate = (int)wav.wave.fmt.sampleRate;
                    if (dialog.ShowDialog() != DialogResult.OK)
                        return;

                    sSTRM strm = STRM.ConvertToSTRM(wav, dialog.Compression);
                    strm.head.loop = (byte)(dialog.Loop ? 0x01 : 0x00);
                    strm.head.loopOffset = (uint)dialog.LoopOffset;

                    STRM.Write(strm, fileout);
                    break;

                case FormatSound.SWAV:
                    sSWAV oldSwav = SWAV.Read(SaveFile());
                    dialog.Compression = oldSwav.data.info.nWaveType;
                    dialog.Loop = (oldSwav.data.info.bLoop != 0 ? true : false);
                    dialog.LoopLength = (int)oldSwav.data.info.nNonLoopLen;
                    dialog.LoopOffset = (int)oldSwav.data.info.nLoopOffset;
                    dialog.SampleRate = (int)wav.wave.fmt.sampleRate;
                    if (dialog.ShowDialog() != DialogResult.OK)
                        return;

                    sSWAV swav = SWAV.ConvertToSWAV(wav, dialog.Compression, dialog.Volume);

                    swav.data.info.bLoop = (byte)(dialog.Loop ? 0x01 : 0x00);
                    swav.data.info.nLoopOffset = (ushort)dialog.LoopOffset;
                    swav.data.info.nNonLoopLen = (uint)dialog.LoopLength;

                    SWAV.Write(swav, fileout);
                    break;
                case FormatSound.SSEQ:
                case FormatSound.SSAR:
                case FormatSound.SBNK:
                case FormatSound.SWAR:
                default:
                    break;
            }

            if (!File.Exists(fileout))
                return;
            ChangeFile((int)selectedFile.id, fileout);
        }