Exemplo n.º 1
0
        private void ExportMidi()
        {
            var filename = lastExportFilename != null ? lastExportFilename : PlatformUtils.ShowSaveFileDialog("Export MIDI File", "MIDI Files (*.mid)|*.mid", ref Settings.LastExportFolder);

            if (filename != null)
            {
                var props             = dialog.GetPropertyPage((int)ExportFormat.Midi);
                var songName          = props.GetPropertyValue <string>(0);
                var velocity          = props.GetPropertyValue <bool>(1);
                var slideNotes        = props.GetPropertyValue <bool>(2);
                var pitchRange        = props.GetPropertyValue <int>(3);
                var instrumentMode    = props.GetSelectedIndex(4);
                var song              = project.GetSong(songName);
                var instrumentMapping = new int[instrumentMode == MidiExportInstrumentMode.Channel ? song.Channels.Length : song.Project.Instruments.Count];

                for (int i = 0; i < instrumentMapping.Length; i++)
                {
                    instrumentMapping[i] = Array.IndexOf(MidiFileReader.MidiInstrumentNames, props.GetPropertyValue <string>(5, i, 1));
                }

                new MidiFileWriter().Save(project, filename, song.Id, instrumentMode, instrumentMapping, velocity, slideNotes, pitchRange);

                lastExportFilename = filename;
            }
        }
Exemplo n.º 2
0
        private void ExportWav()
        {
            var filename = PlatformUtils.ShowSaveFileDialog("Export Wave File", "Wave Audio File (*.wav)|*.wav", ref Settings.LastExportFolder);

            if (filename != null)
            {
                var props            = dialog.GetPropertyPage((int)ExportFormat.Wav);
                var songName         = props.GetPropertyValue <string>(0);
                var sampleRate       = Convert.ToInt32(props.GetPropertyValue <string>(1));
                var loopCount        = props.GetPropertyValue <string>(2) != "Duration" ? props.GetPropertyValue <int>(3) : -1;
                var duration         = props.GetPropertyValue <string>(2) == "Duration" ? props.GetPropertyValue <int>(4) : -1;
                var selectedChannels = props.GetPropertyValue <bool[]>(5);

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

                WaveFile.Save(project.GetSong(songName), filename, sampleRate, loopCount, duration, channelMask);
            }
        }
Exemplo n.º 3
0
        private void ExportVideo()
        {
            var filename = PlatformUtils.ShowSaveFileDialog("Export Video File", "MP4 Video File (*.mp4)|*.mp4", ref Settings.LastExportFolder);

            if (filename != null)
            {
                var zoomValues = new[] { "12.5%", "25%", "50%", "100%", "200%", "400%", "800%" };

                var props            = dialog.GetPropertyPage((int)ExportFormat.Video);
                var ffmpeg           = props.GetPropertyValue <string>(0);
                var songName         = props.GetPropertyValue <string>(2);
                var audioBitRate     = Convert.ToInt32(props.GetPropertyValue <string>(3));
                var videoBitRate     = Convert.ToInt32(props.GetPropertyValue <string>(4));
                var pianoRollZoom    = Array.IndexOf(zoomValues, props.GetPropertyValue <string>(5)) - 3;
                var thinNotes        = props.GetPropertyValue <bool>(6);
                var loopCount        = props.GetPropertyValue <int>(7);
                var selectedChannels = props.GetPropertyValue <bool[]>(8);
                var song             = project.GetSong(songName);

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

                new VideoFile().Save(project, song.Id, loopCount, ffmpeg, filename, channelMask, audioBitRate, videoBitRate, pianoRollZoom, thinNotes);
            }
        }
Exemplo n.º 4
0
        private void ExportFamiTone2Music(bool famiStudio)
        {
            if (!canExportToSoundEngine)
            {
                return;
            }

            var props = dialog.GetPropertyPage(famiStudio ? (int)ExportFormat.FamiStudioMusic : (int)ExportFormat.FamiTone2Music);

            var separate        = props.GetPropertyValue <bool>(1);
            var songIds         = GetSongIds(props.GetPropertyValue <bool[]>(5));
            var kernel          = famiStudio ? FamiToneKernel.FamiStudio : FamiToneKernel.FamiTone2;
            var exportFormat    = AssemblyFormat.GetValueForName(props.GetPropertyValue <string>(0));
            var ext             = exportFormat == AssemblyFormat.CA65 ? "s" : "asm";
            var songNamePattern = props.GetPropertyValue <string>(2);
            var dpcmNamePattern = props.GetPropertyValue <string>(3);
            var generateInclude = props.GetPropertyValue <bool>(4);

            if (separate)
            {
                var folder = lastExportFilename != null ? lastExportFilename : PlatformUtils.ShowBrowseFolderDialog("Select the export folder", ref Settings.LastExportFolder);

                if (folder != null)
                {
                    foreach (var songId in songIds)
                    {
                        var song = project.GetSong(songId);
                        var formattedSongName = songNamePattern.Replace("{project}", project.Name).Replace("{song}", song.Name);
                        var formattedDpcmName = dpcmNamePattern.Replace("{project}", project.Name).Replace("{song}", song.Name);
                        var songFilename      = Path.Combine(folder, Utils.MakeNiceAsmName(formattedSongName) + "." + ext);
                        var dpcmFilename      = Path.Combine(folder, Utils.MakeNiceAsmName(formattedDpcmName) + ".dmc");
                        var includeFilename   = generateInclude ? Path.ChangeExtension(songFilename, null) + "_songlist.inc" : null;

                        Log.LogMessage(LogSeverity.Info, $"Exporting song '{song.Name}' as separate assembly files.");

                        FamitoneMusicFile f = new FamitoneMusicFile(kernel, true);
                        f.Save(project, new int[] { songId }, exportFormat, true, songFilename, dpcmFilename, includeFilename, MachineType.Dual);
                    }

                    lastExportFilename = folder;
                }
            }
            else
            {
                var engineName = famiStudio ? "FamiStudio" : "FamiTone2";
                var filename   = lastExportFilename != null ? lastExportFilename : PlatformUtils.ShowSaveFileDialog($"Export {engineName} Assembly Code", $"{engineName} Assembly File (*.{ext})|*.{ext}", ref Settings.LastExportFolder);
                if (filename != null)
                {
                    var includeFilename = generateInclude ? Path.ChangeExtension(filename, null) + "_songlist.inc" : null;

                    Log.LogMessage(LogSeverity.Info, $"Exporting all songs to a single assembly file.");

                    FamitoneMusicFile f = new FamitoneMusicFile(kernel, true);
                    f.Save(project, songIds, exportFormat, false, filename, Path.ChangeExtension(filename, ".dmc"), includeFilename, MachineType.Dual);

                    lastExportFilename = filename;
                }
            }
        }
Exemplo n.º 5
0
        private void ExportFamiTracker()
        {
            var filename = PlatformUtils.ShowSaveFileDialog("Export FamiTracker Text File", "FamiTracker Text Format (*.txt)|*.txt");

            if (filename != null)
            {
                var props = dialog.GetPropertyPage((int)ExportFormat.FamiTracker);
                FamitrackerFile.Save(project, filename, GetSongIds(props.GetPropertyValue <bool[]>(0)));
            }
        }
Exemplo n.º 6
0
        private void ExportText()
        {
            var filename = PlatformUtils.ShowSaveFileDialog("Export FamiStudio Text File", "FamiStudio Text Export (*.txt)|*.txt", ref Settings.LastExportFolder);

            if (filename != null)
            {
                var props = dialog.GetPropertyPage((int)ExportFormat.Text);
                new FamistudioTextFile().Save(project, filename, GetSongIds(props.GetPropertyValue <bool[]>(0)));
            }
        }
Exemplo n.º 7
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.º 8
0
        private void ExportWav()
        {
            var filename = PlatformUtils.ShowSaveFileDialog("Export Wave File", "Wave Audio File (*.wav)|*.wav");

            if (filename != null)
            {
                var props      = dialog.GetPropertyPage((int)ExportFormat.Wav);
                var songName   = props.GetPropertyValue <string>(0);
                var sampleRate = Convert.ToInt32(props.GetPropertyValue <string>(1));

                WaveFile.Save(project.GetSong(songName), filename, sampleRate);
            }
        }
Exemplo n.º 9
0
        private void ExportFamiTone2Sfx(bool famiStudio)
        {
            var props        = dialog.GetPropertyPage(famiStudio ? (int)ExportFormat.FamiStudioSfx : (int)ExportFormat.FamiTone2Sfx);
            var exportFormat = (AssemblyFormat)Enum.Parse(typeof(AssemblyFormat), props.GetPropertyValue <string>(0));
            var ext          = exportFormat == AssemblyFormat.CA65 ? "s" : "asm";
            var mode         = (MachineType)Enum.Parse(typeof(MachineType), props.GetPropertyValue <string>(1));
            var songIds      = GetSongIds(props.GetPropertyValue <bool[]>(2));

            var filename = PlatformUtils.ShowSaveFileDialog("Export FamiTone2 Code", $"FamiTone2 Assembly File (*.{ext})|*.{ext}", ref Settings.LastExportFolder);

            if (filename != null)
            {
                FamitoneSoundEffectFile f = new FamitoneSoundEffectFile();
                f.Save(project, songIds, exportFormat, mode, filename);
            }
        }
Exemplo n.º 10
0
        private void ExportNsf()
        {
            var filename = PlatformUtils.ShowSaveFileDialog("Export NSF File", "Nintendo Sound Files (*.nsf)|*.nsf");

            if (filename != null)
            {
                var props  = dialog.GetPropertyPage((int)ExportFormat.Nsf);
                var kernel = (FamitoneMusicFile.FamiToneKernel)Enum.Parse(typeof(FamitoneMusicFile.FamiToneKernel), props.GetPropertyValue <string>(5));

                NsfFile.Save(project, kernel, filename,
                             GetSongIds(props.GetPropertyValue <bool[]>(4)),
                             props.GetPropertyValue <string>(0),
                             props.GetPropertyValue <string>(1),
                             props.GetPropertyValue <string>(2));
            }
        }
Exemplo n.º 11
0
        private void ExportFamiTracker()
        {
            if (!canExportToFamiTracker)
            {
                return;
            }

            var props = dialog.GetPropertyPage((int)ExportFormat.FamiTracker);

            var filename = lastExportFilename != null ? lastExportFilename : PlatformUtils.ShowSaveFileDialog("Export FamiTracker Text File", "FamiTracker Text Format (*.txt)|*.txt", ref Settings.LastExportFolder);

            if (filename != null)
            {
                new FamitrackerTextFile().Save(project, filename, GetSongIds(props.GetPropertyValue <bool[]>(0)));
                lastExportFilename = filename;
            }
        }
Exemplo n.º 12
0
        private void ExportMidi()
        {
            var filename = lastExportFilename != null ? lastExportFilename : PlatformUtils.ShowSaveFileDialog("Export MIDI File", "MIDI Files (*.mid)|*.mid", ref Settings.LastExportFolder);

            if (filename != null)
            {
                var props          = dialog.GetPropertyPage((int)ExportFormat.Midi);
                var songName       = props.GetPropertyValue <string>(0);
                var velocity       = props.GetPropertyValue <bool>(1);
                var slideNotes     = props.GetPropertyValue <bool>(2);
                var pitchRange     = props.GetPropertyValue <int>(3);
                var instrumentMode = props.GetSelectedIndex(4);

                new MidiFileWriter().Save(project, filename, project.GetSong(songName).Id, instrumentMode, midiInstrumentMapping, velocity, slideNotes, pitchRange);

                lastExportFilename = filename;
            }
        }
Exemplo n.º 13
0
        private void ExportFamiTone2()
        {
            var props           = dialog.GetPropertyPage((int)ExportFormat.FamiTone2);
            var kernelString    = props.GetPropertyValue <string>(0);
            var formatString    = props.GetPropertyValue <string>(1);
            var ext             = formatString == "CA65" ? "s" : "asm";
            var separate        = props.GetPropertyValue <bool>(2);
            var songIds         = GetSongIds(props.GetPropertyValue <bool[]>(5));
            var kernel          = (FamitoneMusicFile.FamiToneKernel)Enum.Parse(typeof(FamitoneMusicFile.FamiToneKernel), kernelString);
            var exportFormat    = (FamitoneMusicFile.OutputFormat)Enum.Parse(typeof(FamitoneMusicFile.OutputFormat), formatString);
            var songNamePattern = props.GetPropertyValue <string>(3);
            var dpcmNamePattern = props.GetPropertyValue <string>(4);

            if (separate)
            {
                var folderBrowserDialog = new FolderBrowserDialog();
                folderBrowserDialog.Description = "Select the export folder";

                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    foreach (var songId in songIds)
                    {
                        var song = project.GetSong(songId);
                        var formattedSongName = songNamePattern.Replace("{project}", project.Name).Replace("{song}", song.Name);
                        var formattedDpcmName = dpcmNamePattern.Replace("{project}", project.Name).Replace("{song}", song.Name);
                        var songFilename      = Path.Combine(folderBrowserDialog.SelectedPath, Utils.MakeNiceAsmName(formattedSongName) + "." + ext);
                        var dpcmFilename      = Path.Combine(folderBrowserDialog.SelectedPath, Utils.MakeNiceAsmName(formattedDpcmName) + ".dmc");

                        FamitoneMusicFile f = new FamitoneMusicFile(kernel);
                        f.Save(project, new int[] { songId }, exportFormat, true, songFilename, dpcmFilename, MachineType.Dual);
                    }
                }
            }
            else
            {
                var filename = PlatformUtils.ShowSaveFileDialog("Export FamiTone2 Code", $"FamiTone2 Assembly File (*.{ext})|*.{ext}");
                if (filename != null)
                {
                    FamitoneMusicFile f = new FamitoneMusicFile(kernel);
                    f.Save(project, songIds, exportFormat, false, filename, Path.ChangeExtension(filename, ".dmc"), MachineType.Dual);
                }
            }
        }
Exemplo n.º 14
0
        private void ExportRom()
        {
            var props   = dialog.GetPropertyPage((int)ExportFormat.Rom);
            var songIds = GetSongIds(props.GetPropertyValue <bool[]>(4));

            if (songIds.Length > RomFileBase.MaxSongs)
            {
                PlatformUtils.MessageBox($"Please select {RomFileBase.MaxSongs} songs or less.", "ROM Export", MessageBoxButtons.OK);
                return;
            }

            if (props.GetPropertyValue <string>(0) == "NES ROM")
            {
                var filename = lastExportFilename != null ? lastExportFilename : PlatformUtils.ShowSaveFileDialog("Export ROM File", "NES ROM (*.nes)|*.nes", ref Settings.LastExportFolder);
                if (filename != null)
                {
                    var rom = new RomFile();
                    rom.Save(
                        project, filename, songIds,
                        props.GetPropertyValue <string>(1),
                        props.GetPropertyValue <string>(2),
                        props.GetPropertyValue <string>(3) == "PAL");

                    lastExportFilename = filename;
                }
            }
            else
            {
                var filename = lastExportFilename != null ? null : PlatformUtils.ShowSaveFileDialog("Export Famicom Disk", "FDS Disk (*.fds)|*.fds", ref Settings.LastExportFolder);
                if (filename != null)
                {
                    var fds = new FdsFile();
                    fds.Save(
                        project, filename, songIds,
                        props.GetPropertyValue <string>(1),
                        props.GetPropertyValue <string>(2));

                    lastExportFilename = filename;
                }
            }
        }
Exemplo n.º 15
0
        private void ExportFamiTone2Sfx(bool famiStudio)
        {
            var props           = dialog.GetPropertyPage(famiStudio ? (int)ExportFormat.FamiStudioSfx : (int)ExportFormat.FamiTone2Sfx);
            var exportFormat    = AssemblyFormat.GetValueForName(props.GetPropertyValue <string>(0));
            var ext             = exportFormat == AssemblyFormat.CA65 ? "s" : "asm";
            var mode            = MachineType.GetValueForName(props.GetPropertyValue <string>(1));
            var engineName      = famiStudio ? "FamiStudio" : "FamiTone2";
            var generateInclude = props.GetPropertyValue <bool>(2);
            var songIds         = GetSongIds(props.GetPropertyValue <bool[]>(3));

            var filename = lastExportFilename != null ? lastExportFilename : PlatformUtils.ShowSaveFileDialog($"Export {engineName} Code", $"{engineName} Assembly File (*.{ext})|*.{ext}", ref Settings.LastExportFolder);

            if (filename != null)
            {
                var includeFilename = generateInclude ? Path.ChangeExtension(filename, null) + "_sfxlist.inc" : null;

                FamitoneSoundEffectFile f = new FamitoneSoundEffectFile();
                f.Save(project, songIds, exportFormat, mode, famiStudio ? FamiToneKernel.FamiStudio : FamiToneKernel.FamiTone2, filename, includeFilename);
                lastExportFilename = filename;
            }
        }
Exemplo n.º 16
0
        private void ExportRom()
        {
            var props   = dialog.GetPropertyPage((int)ExportFormat.Rom);
            var songIds = GetSongIds(props.GetPropertyValue <bool[]>(2));

            if (songIds.Length > RomFile.MaxSongs)
            {
                PlatformUtils.MessageBox("Please select 8 songs or less.", "ROM Export", MessageBoxButtons.OK);
                return;
            }

            var filename = PlatformUtils.ShowSaveFileDialog("Export ROM File", "NES ROM (*.nes)|*.nes");

            if (filename != null)
            {
                RomFile.Save(project, filename,
                             songIds,
                             props.GetPropertyValue <string>(0),
                             props.GetPropertyValue <string>(1));
            }
        }
Exemplo n.º 17
0
        private void ExportNsf()
        {
            Action <string> ExportNsfAction = (filename) =>
            {
                if (filename != null)
                {
                    var props = dialog.GetPropertyPage((int)ExportFormat.Nsf);
                    var mode  = MachineType.GetValueForName(props.GetPropertyValue <string>(3));
#if DEBUG
                    var kernel = FamiToneKernel.GetValueForName(props.GetPropertyValue <string>(5));
#else
                    var kernel = FamiToneKernel.FamiStudio;
#endif

                    new NsfFile().Save(project, kernel, filename,
                                       GetSongIds(props.GetPropertyValue <bool[]>(4)),
                                       props.GetPropertyValue <string>(0),
                                       props.GetPropertyValue <string>(1),
                                       props.GetPropertyValue <string>(2),
                                       mode);

                    lastExportFilename = filename;
                }
            };

            if (PlatformUtils.IsMobile)
            {
                PlatformUtils.StartMobileSaveFileOperationAsync("*/*", $"{project.Name}.nsf", (f) =>
                {
                    ExportNsfAction(f);
                    PlatformUtils.FinishMobileSaveFileOperationAsync(true, () => { PlatformUtils.ShowToast("NSF Export Successful!"); });
                });
            }
            else
            {
                var filename = lastExportFilename != null ? lastExportFilename : PlatformUtils.ShowSaveFileDialog("Export NSF File", "Nintendo Sound Files (*.nsf)|*.nsf", ref Settings.LastExportFolder);
                ExportNsfAction(filename);
            }
        }
Exemplo n.º 18
0
        private void ExportNsf()
        {
            var filename = PlatformUtils.ShowSaveFileDialog("Export NSF File", "Nintendo Sound Files (*.nsf)|*.nsf", ref Settings.LastExportFolder);

            if (filename != null)
            {
                var props = dialog.GetPropertyPage((int)ExportFormat.Nsf);
                var mode  = (MachineType)Enum.Parse(typeof(MachineType), props.GetPropertyValue <string>(3));
#if DEBUG
                var kernel = (FamitoneMusicFile.FamiToneKernel)Enum.Parse(typeof(FamitoneMusicFile.FamiToneKernel), props.GetPropertyValue <string>(5));
#else
                var kernel = FamitoneMusicFile.FamiToneKernel.FamiStudio;
#endif

                new NsfFile().Save(project, kernel, filename,
                                   GetSongIds(props.GetPropertyValue <bool[]>(4)),
                                   props.GetPropertyValue <string>(0),
                                   props.GetPropertyValue <string>(1),
                                   props.GetPropertyValue <string>(2),
                                   mode);
            }
        }
Exemplo n.º 19
0
        private void ExportVideo()
        {
            var filename = lastExportFilename != null ? lastExportFilename : PlatformUtils.ShowSaveFileDialog("Export Video File", "MP4 Video File (*.mp4)|*.mp4", ref Settings.LastExportFolder);

            if (filename != null)
            {
                var zoomValues = new[] { "12.5%", "25%", "50%", "100%", "200%", "400%", "800%" };
                var frameRates = new[] { "50/60 FPS", "25/30 FPS" };

                var props            = dialog.GetPropertyPage((int)ExportFormat.Video);
                var ffmpeg           = props.GetPropertyValue <string>(0);
                var songName         = props.GetPropertyValue <string>(2);
                var resolutionIdx    = VideoResolution.GetIndexForName(props.GetPropertyValue <string>(3));
                var resolutionX      = VideoResolution.ResolutionX[resolutionIdx];
                var resolutionY      = VideoResolution.ResolutionY[resolutionIdx];
                var halfFrameRate    = Array.IndexOf(frameRates, props.GetPropertyValue <string>(4)) == 1;
                var audioBitRate     = Convert.ToInt32(props.GetPropertyValue <string>(5), CultureInfo.InvariantCulture);
                var videoBitRate     = Convert.ToInt32(props.GetPropertyValue <string>(6), CultureInfo.InvariantCulture);
                var pianoRollZoom    = Array.IndexOf(zoomValues, props.GetPropertyValue <string>(7)) - 3;
                var loopCount        = props.GetPropertyValue <int>(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);
                    }
                }

                new VideoFile().Save(project, song.Id, loopCount, ffmpeg, filename, resolutionX, resolutionY, halfFrameRate, channelMask, audioBitRate, videoBitRate, pianoRollZoom);

                lastExportFilename = filename;
            }
        }
Exemplo n.º 20
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);
            }
        }
Exemplo n.º 21
0
        private void ExportVideo(bool pianoRoll)
        {
            if (!canExportToVideo)
            {
                return;
            }

            var props = dialog.GetPropertyPage(pianoRoll ? (int)ExportFormat.VideoPianoRoll : (int)ExportFormat.VideoOscilloscope);

            Func <string, bool> ExportVideoAction = (filename) =>
            {
                if (filename != null)
                {
                    var stereoPropIdx   = pianoRoll ? 7 : 9;
                    var channelsPropIdx = pianoRoll ? 8 : 10;

                    var songName      = props.GetPropertyValue <string>(0);
                    var resolutionIdx = props.GetSelectedIndex(1);
                    var resolutionX   = VideoResolution.ResolutionX[resolutionIdx];
                    var resolutionY   = VideoResolution.ResolutionY[resolutionIdx];
                    var halfFrameRate = props.GetSelectedIndex(2) == 1;
                    var audioBitRate  = Convert.ToInt32(props.GetPropertyValue <string>(3), CultureInfo.InvariantCulture);
                    var videoBitRate  = Convert.ToInt32(props.GetPropertyValue <string>(4), CultureInfo.InvariantCulture);
                    var loopCount     = props.GetPropertyValue <int>(5);
                    var stereo        = props.GetPropertyValue <bool>(stereoPropIdx);
                    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>(channelsPropIdx, i, 0))
                            {
                                channelMask |= (1 << i);
                            }

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

                    lastExportFilename = filename;

                    if (pianoRoll)
                    {
                        var pianoRollZoom = (float)Math.Pow(2.0, props.GetSelectedIndex(6) - 3);

                        return(new VideoFilePianoRoll().Save(project, song.Id, loopCount, filename, resolutionX, resolutionY, halfFrameRate, channelMask, audioBitRate, videoBitRate, pianoRollZoom, stereo, pan));
                    }
                    else
                    {
                        var oscNumColumns    = props.GetPropertyValue <int>(6);
                        var oscLineThickness = props.GetPropertyValue <int>(7);
                        var oscColorMode     = props.GetSelectedIndex(8);

                        return(new VideoFileOscilloscope().Save(project, song.Id, loopCount, oscColorMode, oscNumColumns, oscLineThickness, filename, resolutionX, resolutionY, halfFrameRate, channelMask, audioBitRate, videoBitRate, stereo, pan));
                    }
                }
                else
                {
                    return(false);
                }
            };

            if (PlatformUtils.IsMobile)
            {
                var songName = props.GetPropertyValue <string>(0);
                PlatformUtils.StartMobileSaveFileOperationAsync("video/mp4", $"{songName}", (f) =>
                {
                    new Thread(() =>
                    {
                        app.BeginLogTask(true);
                        var success = ExportVideoAction(f);

                        PlatformUtils.FinishMobileSaveFileOperationAsync(success, () =>
                        {
                            app.EndLogTask();
                            PlatformUtils.ShowToast($"Video Export {(success ? "Successful" : "Failed")}!");
                        });
                    }).Start();
                });
            }
            else
            {
                var filename = lastExportFilename != null ? lastExportFilename : PlatformUtils.ShowSaveFileDialog("Export Video File", "MP4 Video File (*.mp4)|*.mp4", ref Settings.LastExportFolder);
                ExportVideoAction(filename);
            }
        }
Exemplo n.º 22
0
        private void ExportRom()
        {
            var props   = dialog.GetPropertyPage((int)ExportFormat.Rom);
            var songIds = GetSongIds(props.GetPropertyValue <bool[]>(4));

            if (songIds.Length > RomFileBase.MaxSongs)
            {
                PlatformUtils.MessageBoxAsync($"Please select {RomFileBase.MaxSongs} songs or less.", "ROM Export", MessageBoxButtons.OK);
                return;
            }

            if (props.GetPropertyValue <string>(0) == "NES ROM")
            {
                Action <string> ExportRomAction = (filename) =>
                {
                    if (filename != null)
                    {
                        var rom = new RomFile();
                        rom.Save(
                            project, filename, songIds,
                            props.GetPropertyValue <string>(1),
                            props.GetPropertyValue <string>(2),
                            props.GetPropertyValue <string>(3) == "PAL");

                        lastExportFilename = filename;
                    }
                };

                if (PlatformUtils.IsMobile)
                {
                    PlatformUtils.StartMobileSaveFileOperationAsync("*/*", $"{project.Name}.nes", (f) =>
                    {
                        ExportRomAction(f);
                        PlatformUtils.FinishMobileSaveFileOperationAsync(true, () => { PlatformUtils.ShowToast("NES ROM Export Successful!"); });
                    });
                }
                else
                {
                    var filename = lastExportFilename != null ? lastExportFilename : PlatformUtils.ShowSaveFileDialog("Export ROM File", "NES ROM (*.nes)|*.nes", ref Settings.LastExportFolder);
                    ExportRomAction(filename);
                }
            }
            else
            {
                Action <string> ExportFdsAction = (filename) =>
                {
                    if (filename != null)
                    {
                        var fds = new FdsFile();
                        fds.Save(
                            project, filename, songIds,
                            props.GetPropertyValue <string>(1),
                            props.GetPropertyValue <string>(2));

                        lastExportFilename = filename;
                    }
                };

                if (PlatformUtils.IsMobile)
                {
                    PlatformUtils.StartMobileSaveFileOperationAsync("*/*", $"{project.Name}.fds", (f) =>
                    {
                        ExportFdsAction(f);
                        PlatformUtils.FinishMobileSaveFileOperationAsync(true, () => { PlatformUtils.ShowToast("FDS Disk Export Successful!"); });
                    });
                }
                else
                {
                    var filename = lastExportFilename != null ? null : PlatformUtils.ShowSaveFileDialog("Export Famicom Disk", "FDS Disk (*.fds)|*.fds", ref Settings.LastExportFolder);
                    ExportFdsAction(filename);
                }
            }
        }
Exemplo n.º 23
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);
                    }
                }
            }
        }