Exemplo n.º 1
0
        private void ExportWavMp3()
        {
            var props  = dialog.GetPropertyPage((int)ExportFormat.WavMp3);
            var format = props.GetPropertyValue <string>(1);

            var filename = "";

            if (format == "MP3")
            {
                filename = lastExportFilename != null ? lastExportFilename : PlatformUtils.ShowSaveFileDialog("Export MP3 File", "MP3 Audio File (*.mp3)|*.mp3", ref Settings.LastExportFolder);
            }
            else
            {
                filename = lastExportFilename != null ? lastExportFilename : PlatformUtils.ShowSaveFileDialog("Export Wave File", "Wave Audio File (*.wav)|*.wav", ref Settings.LastExportFolder);
            }

            if (filename != null)
            {
                var songName         = props.GetPropertyValue <string>(0);
                var sampleRate       = Convert.ToInt32(props.GetPropertyValue <string>(2), CultureInfo.InvariantCulture);
                var bitRate          = Convert.ToInt32(props.GetPropertyValue <string>(3), CultureInfo.InvariantCulture);
                var loopCount        = props.GetPropertyValue <string>(4) != "Duration" ? props.GetPropertyValue <int>(5) : -1;
                var duration         = props.GetPropertyValue <string>(4) == "Duration" ? props.GetPropertyValue <int>(6) : -1;
                var separateFiles    = props.GetPropertyValue <bool>(7);
                var separateIntro    = props.GetPropertyValue <bool>(8);
                var selectedChannels = props.GetPropertyValue <bool[]>(9);
                var song             = project.GetSong(songName);

                var channelMask = 0;
                for (int i = 0; i < selectedChannels.Length; i++)
                {
                    if (selectedChannels[i])
                    {
                        channelMask |= (1 << i);
                    }
                }

                WavMp3ExportUtils.Save(song, filename, sampleRate, loopCount, duration, channelMask, separateFiles, separateIntro,
                                       (samples, fn) =>
                {
                    if (format == "MP3")
                    {
                        Mp3File.Save(samples, fn, sampleRate, bitRate);
                    }
                    else
                    {
                        WaveFile.Save(samples, fn, sampleRate);
                    }
                });

                lastExportFilename = filename;
            }
        }
Exemplo n.º 2
0
        private void AudioExport(string filename, int format)
        {
            var extension = format == AudioFormatType.Mp3 ? "mp3" : (format == AudioFormatType.Vorbis ? "ogg" : "wav");

            if (!ValidateExtension(filename, "." + extension))
            {
                return;
            }

            var songIndex  = ParseOption("export-song", 0);
            var sampleRate = ParseOption($"{extension}-export-rate", 44100);
            var loopCount  = ParseOption($"{extension}-export-loop", 1);
            var duration   = ParseOption($"{extension}-export-duration", 0);
            var mask       = ParseOption($"{extension}-export-channels", 0xff, true);
            var separate   = HasOption($"{extension}-export-separate-channels");
            var intro      = HasOption($"{extension}-export-separate-intro");
            var bitrate    = ParseOption($"{extension}-export-bitrate", 192);
            var song       = GetProjectSong(songIndex);

            if (duration > 0)
            {
                loopCount = -1;
            }
            else
            {
                loopCount = Math.Max(1, loopCount);
            }

            if (song != null)
            {
                AudioExportUtils.Save(song, filename, sampleRate, loopCount, duration, mask, separate, intro, false, null,
                                      (samples, samplesChannels, fn) =>
                {
                    switch (format)
                    {
                    case AudioFormatType.Mp3:
                        Mp3File.Save(samples, fn, sampleRate, bitrate, samplesChannels);
                        break;

                    case AudioFormatType.Wav:
                        WaveFile.Save(samples, fn, sampleRate, samplesChannels);
                        break;

                    case AudioFormatType.Vorbis:
                        VorbisFile.Save(samples, fn, sampleRate, bitrate, samplesChannels);
                        break;
                    }
                });
            }
        }
Exemplo n.º 3
0
        private void WavMp3Export(string filename, bool mp3)
        {
            var extension = mp3 ? "mp3" : "wav";

            if (!ValidateExtension(filename, "." + extension))
            {
                return;
            }

            var songIndex  = ParseOption("export-song", 0);
            var sampleRate = ParseOption($"{extension}-export-rate", 44100);
            var loopCount  = ParseOption($"{extension}-export-loop", 1);
            var duration   = ParseOption($"{extension}-export-duration", 0);
            var mask       = ParseOption($"{extension}-export-channels", 0xff, true);
            var separate   = HasOption($"{extension}-export-separate-channels");
            var intro      = HasOption($"{extension}-export-separate-intro");
            var bitrate    = ParseOption($"{extension}-export-bitrate", 192);
            var song       = GetProjectSong(songIndex);

            if (duration > 0)
            {
                loopCount = -1;
            }
            else
            {
                loopCount = Math.Max(1, loopCount);
            }

            if (song != null)
            {
                WavMp3ExportUtils.Save(song, filename, sampleRate, loopCount, duration, mask, separate, intro,
                                       (samples, fn) =>
                {
                    if (mp3)
                    {
                        Mp3File.Save(samples, fn, sampleRate, bitrate);
                    }
                    else
                    {
                        WaveFile.Save(samples, fn, sampleRate);
                    }
                });
            }
        }
Exemplo n.º 4
0
        private void WavMp3Export(string filename, bool mp3)
        {
            var extension = mp3 ? "mp3" : "wav";

            if (!ValidateExtension(filename, "." + extension))
            {
                return;
            }

            var songIndex  = ParseOption("export-song", 0);
            var sampleRate = ParseOption($"{extension}-export-rate", 44100);
            var loopCount  = ParseOption($"{extension}-export-loop", 1);
            var duration   = ParseOption($"{extension}-export-duration", 0);
            var mask       = ParseOption($"{extension}-export-channels", 0xff, true);
            var separate   = HasOption($"{extension}-export-separate-channels");
            var bitrate    = ParseOption($"{extension}-export-bitrate", 192);
            var song       = GetProjectSong(songIndex);

            if (duration > 0)
            {
                loopCount = -1;
            }
            else
            {
                loopCount = Math.Max(1, loopCount);
            }

            if (song != null)
            {
                if (separate)
                {
                    for (int i = 0; i < song.Channels.Length; i++)
                    {
                        if ((mask & (1 << i)) != 0)
                        {
                            var channelFilename = Utils.AddFileSuffix(filename, "_" + song.Channels[i].ExportName);

                            if (mp3)
                            {
                                Mp3File.Save(song, channelFilename, sampleRate, bitrate, loopCount, duration, 1 << i);
                            }
                            else
                            {
                                WaveFile.Save(song, channelFilename, sampleRate, loopCount, duration, 1 << i);
                            }
                        }
                    }
                }
                else
                {
                    if (mp3)
                    {
                        Mp3File.Save(song, filename, sampleRate, bitrate, loopCount, duration, mask);
                    }
                    else
                    {
                        WaveFile.Save(song, filename, sampleRate, loopCount, duration, mask);
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void ExportWavMp3()
        {
            var props  = dialog.GetPropertyPage((int)ExportFormat.WavMp3);
            var format = props.GetPropertyValue <string>(1);

            var filename = "";

            if (format == "MP3")
            {
                filename = PlatformUtils.ShowSaveFileDialog("Export MP3 File", "MP3 Audio File (*.mp3)|*.mp3", ref Settings.LastExportFolder);
            }
            else
            {
                filename = PlatformUtils.ShowSaveFileDialog("Export Wave File", "Wave Audio File (*.wav)|*.wav", ref Settings.LastExportFolder);
            }

            if (filename != null)
            {
                var songName         = props.GetPropertyValue <string>(0);
                var sampleRate       = Convert.ToInt32(props.GetPropertyValue <string>(2));
                var bitRate          = Convert.ToInt32(props.GetPropertyValue <string>(3));
                var loopCount        = props.GetPropertyValue <string>(4) != "Duration" ? props.GetPropertyValue <int>(5) : -1;
                var duration         = props.GetPropertyValue <string>(4) == "Duration" ? props.GetPropertyValue <int>(6) : -1;
                var separateFiles    = props.GetPropertyValue <bool>(7);
                var selectedChannels = props.GetPropertyValue <bool[]>(8);
                var song             = project.GetSong(songName);

                if (separateFiles)
                {
                    for (int i = 0; i < selectedChannels.Length; i++)
                    {
                        if (selectedChannels[i])
                        {
                            var channelFilename = Utils.AddFileSuffix(filename, "_" + song.Channels[i].ExportName);

                            if (format == "MP3")
                            {
                                Mp3File.Save(song, channelFilename, sampleRate, bitRate, loopCount, duration, 1 << i);
                            }
                            else
                            {
                                WaveFile.Save(song, channelFilename, sampleRate, loopCount, duration, 1 << i);
                            }
                        }
                    }
                }
                else
                {
                    var channelMask = 0;
                    for (int i = 0; i < selectedChannels.Length; i++)
                    {
                        if (selectedChannels[i])
                        {
                            channelMask |= (1 << i);
                        }
                    }

                    if (format == "MP3")
                    {
                        Mp3File.Save(song, filename, sampleRate, bitRate, loopCount, duration, channelMask);
                    }
                    else
                    {
                        WaveFile.Save(song, filename, sampleRate, loopCount, duration, channelMask);
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void ExportWavMp3()
        {
            var props  = dialog.GetPropertyPage((int)ExportFormat.WavMp3);
            var format = props.GetSelectedIndex(1);

            Action <string> ExportWavMp3Action = (filename) =>
            {
                if (filename != null)
                {
                    var songName      = props.GetPropertyValue <string>(0);
                    var sampleRate    = Convert.ToInt32(props.GetPropertyValue <string>(2), CultureInfo.InvariantCulture);
                    var bitrate       = Convert.ToInt32(props.GetPropertyValue <string>(3), CultureInfo.InvariantCulture);
                    var loopCount     = props.GetPropertyValue <string>(4) != "Duration" ? props.GetPropertyValue <int>(5) : -1;
                    var duration      = props.GetPropertyValue <string>(4) == "Duration" ? props.GetPropertyValue <int>(6) : -1;
                    var separateFiles = props.GetPropertyValue <bool>(7);
                    var separateIntro = props.GetPropertyValue <bool>(8);
                    var stereo        = props.GetPropertyValue <bool>(9) && !separateFiles;
                    var song          = project.GetSong(songName);

                    var channelCount = project.GetActiveChannelCount();
                    var channelMask  = 0;
                    var pan          = (float[])null;

                    if (PlatformUtils.IsDesktop)
                    {
                        pan = new float[channelCount];

                        for (int i = 0; i < channelCount; i++)
                        {
                            if (props.GetPropertyValue <bool>(10, i, 0))
                            {
                                channelMask |= (1 << i);
                            }

                            pan[i] = props.GetPropertyValue <int>(10, i, 2) / 100.0f;
                        }
                    }
                    else
                    {
                        var selectedChannels = props.GetPropertyValue <bool[]>(10);
                        for (int i = 0; i < channelCount; i++)
                        {
                            if (selectedChannels[i])
                            {
                                channelMask |= (1 << i);
                            }
                        }
                    }

                    AudioExportUtils.Save(song, filename, sampleRate, loopCount, duration, channelMask, separateFiles, separateIntro, stereo, pan,
                                          (samples, samplesChannels, fn) =>
                    {
                        switch (format)
                        {
                        case AudioFormatType.Mp3:
                            Mp3File.Save(samples, fn, sampleRate, bitrate, samplesChannels);
                            break;

                        case AudioFormatType.Wav:
                            WaveFile.Save(samples, fn, sampleRate, samplesChannels);
                            break;

                        case AudioFormatType.Vorbis:
                            VorbisFile.Save(samples, fn, sampleRate, bitrate, samplesChannels);
                            break;
                        }
                    });

                    lastExportFilename = filename;
                }
            };

            if (PlatformUtils.IsMobile)
            {
                var songName = props.GetPropertyValue <string>(0);
                PlatformUtils.StartMobileSaveFileOperationAsync(AudioFormatType.MimeTypes[format], $"{songName}", (f) =>
                {
                    ExportWavMp3Action(f);
                    PlatformUtils.FinishMobileSaveFileOperationAsync(true, () => { PlatformUtils.ShowToast("Audio Export Successful!"); });
                });
            }
            else
            {
                var filename = (string)null;

                if (lastExportFilename != null)
                {
                    filename = lastExportFilename;
                }
                else
                {
                    filename = PlatformUtils.ShowSaveFileDialog(
                        $"Export {AudioFormatType.Names[format]} File",
                        $"{AudioFormatType.Names[format]} Audio File (*.{AudioFormatType.Extensions[format]})|*.{AudioFormatType.Extensions[format]}",
                        ref Settings.LastExportFolder);
                }

                ExportWavMp3Action(filename);
            }
        }