示例#1
0
 private void Page_PropertyChanged(PropertyPage props, int idx, object value)
 {
     if (props == dialog.GetPropertyPage((int)ExportFormat.FamiTone2) && idx == 1)
     {
         props.SetPropertyEnabled(2, (bool)value);
         props.SetPropertyEnabled(3, (bool)value);
     }
 }
示例#2
0
 private void Page_PropertyChanged(PropertyPage props, int idx, object value)
 {
     if (props == dialog.GetPropertyPage((int)ExportFormat.FamiTone2Music) && idx == 2)
     {
         props.SetPropertyEnabled(3, (bool)value);
         props.SetPropertyEnabled(4, (bool)value);
     }
     else if (props == dialog.GetPropertyPage((int)ExportFormat.Wav) && idx == 2)
     {
         props.SetPropertyEnabled(3, (string)value == "Duration");
     }
 }
示例#3
0
        private void SongCleanup()
        {
            var props   = dialog.GetPropertyPage((int)TransformOperation.SongCleanup);
            var songIds = GetSongIds(props.GetPropertyValue <bool[]>(3));

            var mergeIdenticalPatterns = props.GetPropertyValue <bool>(0);
            var deleteEmptyPatterns    = props.GetPropertyValue <bool>(1);
            var reduceNoteLengths      = props.GetPropertyValue <bool>(2);

            if (songIds.Length > 0 && (mergeIdenticalPatterns || deleteEmptyPatterns || reduceNoteLengths))
            {
                app.UndoRedoManager.BeginTransaction(TransactionScope.Project);

                CleaningUp?.Invoke();

                foreach (var songId in songIds)
                {
                    app.Project.GetSong(songId).DeleteNotesPastMaxInstanceLength();
                }

                if (reduceNoteLengths)
                {
                    foreach (var songId in songIds)
                    {
                        app.Project.GetSong(songId).SetNoteDurationToMaximumLength();
                    }
                }

                if (mergeIdenticalPatterns)
                {
                    foreach (var songId in songIds)
                    {
                        app.Project.GetSong(songId).MergeIdenticalPatterns();
                    }
                }

                if (deleteEmptyPatterns)
                {
                    foreach (var songId in songIds)
                    {
                        app.Project.GetSong(songId).DeleteEmptyPatterns();
                    }
                }

                app.UndoRedoManager.EndTransaction();
            }
        }
示例#4
0
        private void UpdateMidiInstrumentMapping()
        {
            var props = dialog.GetPropertyPage((int)ExportFormat.Midi);
            var mode  = props.GetSelectedIndex(4);
            var data  = (string[, ])null;
            var cols  = new[] { "", "MIDI Instrument" };

            if (mode == MidiExportInstrumentMode.Instrument)
            {
                if (midiInstrumentMapping == null)
                {
                    midiInstrumentMapping = new int[project.Instruments.Count];
                }

                data = new string[project.Instruments.Count, 2];
                for (int i = 0; i < project.Instruments.Count; i++)
                {
                    data[i, 0] = project.Instruments[i].Name;
                    data[i, 1] = MidiFileReader.MidiInstrumentNames[midiInstrumentMapping[i]];
                }

                cols[0] = "FamiStudio Instrument";
            }
            else
            {
                var firstSong = project.Songs[0];

                if (midiInstrumentMapping == null)
                {
                    midiInstrumentMapping = new int[firstSong.Channels.Length];
                }

                data = new string[firstSong.Channels.Length, 2];
                for (int i = 0; i < firstSong.Channels.Length; i++)
                {
                    data[i, 0] = firstSong.Channels[i].Name;
                    data[i, 1] = MidiFileReader.MidiInstrumentNames[midiInstrumentMapping[i]];
                }

                cols[0] = "NES Channel";
            }

            props.UpdateMultiColumnList(6, data, cols);
        }
示例#5
0
        private void Cleanup()
        {
            var props   = dialog.GetPropertyPage((int)TransformOperation.Cleanup);
            var songIds = GetSongIds(props.GetPropertyValue <bool[]>(5));

            var mergeIdenticalPatterns    = props.GetPropertyValue <bool>(0);
            var deleteEmptyPatterns       = props.GetPropertyValue <bool>(1);
            var mergeIdenticalInstruments = props.GetPropertyValue <bool>(2);
            var deleteUnusedInstruments   = props.GetPropertyValue <bool>(3);
            var deleteUnusedSamples       = props.GetPropertyValue <bool>(4);

            if (songIds.Length > 0 && (mergeIdenticalPatterns || deleteEmptyPatterns || mergeIdenticalInstruments || deleteUnusedInstruments || deleteUnusedSamples))
            {
                app.UndoRedoManager.BeginTransaction(TransactionScope.Project);

                foreach (var songId in songIds)
                {
                    app.Project.GetSong(songId).DeleteNotesPastMaxInstanceLength();
                }

                if (mergeIdenticalPatterns)
                {
                    foreach (var songId in songIds)
                    {
                        var song = app.Project.GetSong(songId);
                        song.MergeIdenticalPatterns();
                    }
                }

                if (deleteEmptyPatterns)
                {
                    foreach (var songId in songIds)
                    {
                        var song = app.Project.GetSong(songId);
                        song.DeleteEmptyPatterns();
                    }
                }

                if (mergeIdenticalInstruments)
                {
                    app.Project.MergeIdenticalInstruments();
                }

                if (deleteUnusedInstruments)
                {
                    app.Project.DeleteUnusedInstruments();
                }

                if (deleteUnusedSamples)
                {
                    app.Project.DeleteUnusedSamples();
                }

                app.UndoRedoManager.EndTransaction();
            }
        }
示例#6
0
 private void Page_PropertyChanged(PropertyPage props, int idx, object value)
 {
     if ((props == dialog.GetPropertyPage((int)ExportFormat.FamiTone2Music) || props == dialog.GetPropertyPage((int)ExportFormat.FamiStudioMusic)) && idx == 1)
     {
         props.SetPropertyEnabled(2, (bool)value);
         props.SetPropertyEnabled(3, (bool)value);
     }
     else if (props == dialog.GetPropertyPage((int)ExportFormat.WavMp3))
     {
         if (idx == 1)
         {
             props.SetPropertyEnabled(3, (string)value == "MP3");
         }
         else if (idx == 4)
         {
             props.SetPropertyEnabled(5, (string)value != "Duration");
             props.SetPropertyEnabled(6, (string)value == "Duration");
         }
     }
 }
示例#7
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);
            }
        }