Esempio n. 1
0
        private void ExportShare()
        {
            var props = dialog.GetPropertyPage((int)ExportFormat.Share);
            var share = props.GetSelectedIndex(0) == 1;

            var filename = !string.IsNullOrEmpty(app.Project.Filename) ? Path.GetFileName(app.Project.Filename) : $"{project.Name}.fms";

            if (share)
            {
                filename = PlatformUtils.GetShareFilename(filename);
                app.SaveProjectCopy(filename);
                PlatformUtils.StartShareFileAsync(filename, () =>
                {
                    PlatformUtils.ShowToast("Sharing Successful!");
                });
            }
            else
            {
                PlatformUtils.StartMobileSaveFileOperationAsync("*/*", filename, (f) =>
                {
                    app.SaveProjectCopy(f);
                    PlatformUtils.FinishMobileSaveFileOperationAsync(true, () => { PlatformUtils.ShowToast("Sharing Successful!"); });
                });
            }
        }
Esempio n. 2
0
 private void Properties_PropertyClicked(PropertyPage props, ClickType click, int propIdx, int rowIdx, int colIdx)
 {
     if (saveMode)
     {
         var idx = dialog.Properties.GetSelectedIndex(0);
         if (idx >= 0 && idx < userProjects.Count - 1)
         {
             PlatformUtils.MessageBoxAsync("Delete project?", "Delete", MessageBoxButtons.YesNo, (r) =>
             {
                 if (r == DialogResult.Yes)
                 {
                     File.Delete(GetUserProjectFilename(userProjects[idx]));
                     userProjects.RemoveAt(idx);
                     props.UpdateRadioButtonList(0, userProjects.ToArray(), userProjects.Count - 1);
                     props.SetPropertyEnabled(1, true);
                     props.SetPropertyEnabled(2, false);
                     PlatformUtils.ShowToast("Project Deleted!");
                 }
             });
         }
     }
     else
     {
         // HACK : We dont support nested activities right now, so return
         // this special code to signal that we should open from storage.
         storageFilename = "///STORAGE///";
         dialog.CloseWithResult(DialogResult.OK);
     }
 }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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);
                }
            }
        }
Esempio n. 5
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);
            }
        }
Esempio 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);
            }
        }