コード例 #1
0
ファイル: ExportTest.cs プロジェクト: terminar/PresetMagician
        private void TestExportInternal(Plugin.PluginTypes pluginType, string expectedExtension)
        {
            var outputDir = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\PresetExport");

            Directory.CreateDirectory(outputDir);

            foreach (var file in Directory.EnumerateFiles(outputDir, "*", SearchOption.AllDirectories))
            {
                File.Delete(file);
            }

            var plugin = GetTestPlugin(pluginType);

            TestBankPath1Levels(outputDir, pluginType, expectedExtension);
            TestBankPath2Levels(outputDir, pluginType, expectedExtension);
            TestBankPath3Levels(outputDir, pluginType, expectedExtension);
            TestBankPath4Levels(outputDir, pluginType, expectedExtension);

            var existingDefaultPreset = new Preset();

            existingDefaultPreset.Plugin              = plugin;
            existingDefaultPreset.PresetId            = "a6d4d311-6856-ffff-863b-d90b3240b085";
            existingDefaultPreset.Metadata.PresetName = "Default";
            existingDefaultPreset.Metadata.BankPath   = "Factory/Default/Crazy";

            var exporter = new NKSExport(null);
            var existingPresetExportInfo = new PresetExportInfo(existingDefaultPreset);

            existingPresetExportInfo.UserContentDirectory = outputDir;
            existingPresetExportInfo.FolderMode           = PresetExportInfo.FolderExportMode.ONE_LEVEL_LAST_BANK;

            exporter.ExportNKSPreset(existingPresetExportInfo, new byte[] { 0xFF });

            existingDefaultPreset.PresetId = "ffffff11-6856-ffff-863b-d90b3240b085";

            existingPresetExportInfo = new PresetExportInfo(existingDefaultPreset);
            existingPresetExportInfo.UserContentDirectory = outputDir;
            existingPresetExportInfo.FolderMode           = PresetExportInfo.FolderExportMode.ONE_LEVEL_LAST_BANK;

            existingPresetExportInfo.CanExport().Should().BeFalse();

            existingPresetExportInfo = new PresetExportInfo(existingDefaultPreset);
            existingPresetExportInfo.UserContentDirectory = outputDir;
            existingPresetExportInfo.FolderMode           = PresetExportInfo.FolderExportMode.ONE_LEVEL_LAST_BANK;
            existingPresetExportInfo.OverwriteMode        = PresetExportInfo.FileOverwriteMode.APPEND_GUID;

            MakeRelative(existingPresetExportInfo).Should()
            .Be(@"SuperDuperPlugin\Crazy\Default.ffffff11-6856-ffff-863b-d90b3240b085" + expectedExtension);

            existingPresetExportInfo = new PresetExportInfo(existingDefaultPreset);
            existingPresetExportInfo.UserContentDirectory = outputDir;
            existingPresetExportInfo.FolderMode           = PresetExportInfo.FolderExportMode.ONE_LEVEL_LAST_BANK;
            existingPresetExportInfo.OverwriteMode        = PresetExportInfo.FileOverwriteMode.FORCE_OVERWRITE;

            MakeRelative(existingPresetExportInfo).Should()
            .Be(@"SuperDuperPlugin\Crazy\Default" + expectedExtension);
        }
コード例 #2
0
 public void ExportNks(Guid pluginGuid, PresetExportInfo preset, byte[] presetData)
 {
     App.Ping();
     try
     {
         var exporter = new NKSExport(_vstHost);
         exporter.ExportNKSPreset(preset, presetData);
     }
     catch (Exception e)
     {
         throw GetFaultException <GenericFault>(e);
     }
 }
コード例 #3
0
        public void ExportNKSPreset(PresetExportInfo preset, byte[] data)
        {
            var nksf = new NKSFRiff();


            nksf.kontaktSound.summaryInformation.summaryInformation.vendor = preset.PluginVendor;
            nksf.kontaktSound.summaryInformation.summaryInformation.uuid   = preset.PresetGuid;
            nksf.kontaktSound.summaryInformation.summaryInformation.name   = preset.PresetName;

            if (preset.PluginType == Plugin.PluginTypes.Instrument)
            {
                nksf.kontaktSound.summaryInformation.summaryInformation.deviceType = "INST";
            }
            else if (preset.PluginType == Plugin.PluginTypes.Effect)
            {
                nksf.kontaktSound.summaryInformation.summaryInformation.deviceType = "FX";
            }
            else
            {
                throw new ArgumentException("Unknown device type");
            }

            nksf.kontaktSound.summaryInformation.summaryInformation.bankChain.Add(preset.PluginName);

            nksf.kontaktSound.summaryInformation.summaryInformation.bankChain.AddRange(preset.BankPath);

            nksf.kontaktSound.summaryInformation.summaryInformation.Types  = preset.Types;
            nksf.kontaktSound.summaryInformation.summaryInformation.Modes  = preset.Modes;
            nksf.kontaktSound.summaryInformation.summaryInformation.author = preset.Author;

            nksf.kontaktSound.summaryInformation.summaryInformation.comment =
                preset.Comment + Environment.NewLine + "Generated with PresetMagician";
            nksf.kontaktSound.pluginId.pluginId.VSTMagic = (uint)preset.PluginId;
            nksf.kontaktSound.pluginChunk.PresetData     = data;

            if (preset.DefaultControllerAssignments != null)
            {
                nksf.kontaktSound.controllerAssignments.controllerAssignments =
                    preset.DefaultControllerAssignments;
            }

            var outputFilename = preset.GetFullOutputPath();

            Directory.CreateDirectory(Path.GetDirectoryName(outputFilename));
            var fileStream2 = new FileStream(outputFilename, FileMode.Create);

            nksf.Write(fileStream2);
            fileStream2.Close();
        }
コード例 #4
0
ファイル: ExportTest.cs プロジェクト: terminar/PresetMagician
        private void TestBankPath3Levels(string outputDir, Plugin.PluginTypes pluginType, string expectedExtension)
        {
            var plugin = GetTestPlugin(pluginType);

            var preset = new Preset();

            preset.Plugin              = plugin;
            preset.PresetId            = "a6d4d311-6856-4fe7-863b-d90b3240b085";
            preset.Metadata.PresetName = "Preset$!#";
            preset.Metadata.BankPath   = "Factory/Default/Crazy";

            var presetExportInfo = new PresetExportInfo(preset);

            presetExportInfo.UserContentDirectory = outputDir;

            presetExportInfo.FolderMode = PresetExportInfo.FolderExportMode.SINGLE_FOLDER;

            MakeRelative(presetExportInfo).Should().Be(@"SuperDuperPlugin\Preset$!#" + expectedExtension);
            MakePreviewRelative(presetExportInfo, true).Should().Be(@"SuperDuperPlugin\.previews\Preset$!#" + expectedExtension + ".wav");
            MakePreviewRelative(presetExportInfo).Should().Be(@"SuperDuperPlugin\.previews\Preset$!#" + expectedExtension + ".ogg");

            presetExportInfo.FolderMode = PresetExportInfo.FolderExportMode.ONE_LEVEL_FIRST_BANK;

            MakeRelative(presetExportInfo).Should().Be(@"SuperDuperPlugin\Factory\Preset$!#" + expectedExtension);
            MakePreviewRelative(presetExportInfo, true).Should().Be(@"SuperDuperPlugin\Factory\.previews\Preset$!#" + expectedExtension + ".wav");
            MakePreviewRelative(presetExportInfo).Should().Be(@"SuperDuperPlugin\Factory\.previews\Preset$!#" + expectedExtension + ".ogg");

            presetExportInfo.FolderMode = PresetExportInfo.FolderExportMode.ONE_LEVEL_LAST_BANK;

            MakeRelative(presetExportInfo).Should().Be(@"SuperDuperPlugin\Crazy\Preset$!#" + expectedExtension);
            MakePreviewRelative(presetExportInfo, true).Should().Be(@"SuperDuperPlugin\Crazy\.previews\Preset$!#" + expectedExtension + ".wav");
            MakePreviewRelative(presetExportInfo).Should().Be(@"SuperDuperPlugin\Crazy\.previews\Preset$!#" + expectedExtension + ".ogg");

            presetExportInfo.FolderMode = PresetExportInfo.FolderExportMode.SUBFOLDERS_TRIMMED;

            MakeRelative(presetExportInfo).Should().Be(@"SuperDuperPlugin\Factory\Default - Crazy\Preset$!#" + expectedExtension);
            MakePreviewRelative(presetExportInfo, true).Should().Be(@"SuperDuperPlugin\Factory\Default - Crazy\.previews\Preset$!#" + expectedExtension + ".wav");
            MakePreviewRelative(presetExportInfo).Should().Be(@"SuperDuperPlugin\Factory\Default - Crazy\.previews\Preset$!#" + expectedExtension + ".ogg");

            presetExportInfo.FolderMode = PresetExportInfo.FolderExportMode.SUBFOLDERS;

            MakeRelative(presetExportInfo).Should().Be(@"SuperDuperPlugin\Factory\Default\Crazy\Preset$!#" + expectedExtension);
            MakePreviewRelative(presetExportInfo, true).Should().Be(@"SuperDuperPlugin\Factory\Default\Crazy\.previews\Preset$!#" + expectedExtension + ".wav");
            MakePreviewRelative(presetExportInfo).Should().Be(@"SuperDuperPlugin\Factory\Default\Crazy\.previews\Preset$!#" + expectedExtension + ".ogg");
        }
コード例 #5
0
        public void ExportNksAudioPreview(Guid pluginGuid, PresetExportInfo preset, byte[] presetData,
                                          int initialDelay)
        {
            App.Ping();
            var plugin = GetPluginByGuid(pluginGuid);

            if (!plugin.IsLoaded)
            {
                throw GetFaultException <PluginNotLoadedFault>();
            }

            try
            {
                var exporter = new NKSExport(_vstHost);
                exporter.ExportPresetAudioPreviewRealtime(plugin, preset, presetData, initialDelay);
            }
            catch (Exception e)
            {
                throw GetFaultException <GenericFault>(e);
            }
        }
コード例 #6
0
ファイル: ExportTest.cs プロジェクト: terminar/PresetMagician
 private string MakePreviewRelative(PresetExportInfo presetExportInfo, bool wav = false)
 {
     return(presetExportInfo.GetPreviewFilename(wav).Replace(presetExportInfo.UserContentDirectory + @"\", ""));
 }
コード例 #7
0
ファイル: ExportTest.cs プロジェクト: terminar/PresetMagician
 private string MakeRelative(PresetExportInfo presetExportInfo)
 {
     return(presetExportInfo.GetFullOutputPath().Replace(presetExportInfo.UserContentDirectory + @"\", ""));
 }
コード例 #8
0
 public void ExportNks(PresetExportInfo preset, byte[] presetData)
 {
     _remoteVstService.ExportNks(_guid, preset, presetData);
 }
コード例 #9
0
 public void ExportNksAudioPreview(PresetExportInfo preset, byte[] presetData,
                                   int initialDelay)
 {
     _remoteVstService.ExportNksAudioPreview(_guid, preset, presetData, initialDelay);
 }
コード例 #10
0
ファイル: Program.cs プロジェクト: terminar/PresetMagician
 public void ExportNks(Guid pluginGuid, PresetExportInfo preset, byte[] presetData)
 {
 }
コード例 #11
0
ファイル: Program.cs プロジェクト: terminar/PresetMagician
 public void ExportNksAudioPreview(Guid pluginGuid, PresetExportInfo preset, byte[] presetData,
                                   int initialDelay)
 {
 }
コード例 #12
0
        public void ExportPresetAudioPreviewRealtime(RemoteVstPlugin plugin, PresetExportInfo preset, byte[] data,
                                                     int initialDelay)
        {
            var ctx = plugin.PluginContext;

            if ((ctx.PluginCommandStub.PluginContext.PluginInfo.Flags & VstPluginFlags.IsSynth) == 0)
            {
                throw new EffectsNotSupportedException();
            }

            // check if the plugin supports real time processing
            if (ctx.PluginCommandStub.CanDo(VstCanDoHelper.ToString(VstPluginCanDo.NoRealTime)) == VstCanDoResult.Yes)
            {
                throw new NoRealtimeProcessingException();
            }

            //ctx.PluginCommandStub.SetChunk(data, false);


            var tempFileName = preset.GetPreviewFilename(true);

            Directory.CreateDirectory(Path.GetDirectoryName(tempFileName));

            var noteOnEvents  = new List <(int loop, int offset, byte note)>();
            var noteOffEvents = new List <(int loop, int offset, byte note)>();

            foreach (var note in preset.PreviewNotePlayer.PreviewNotes)
            {
                var onLoop   = (double)VstHost.SampleRate * note.Start / VstHost.BlockSize;
                var onOffset = (int)((onLoop - (int)onLoop) * VstHost.BlockSize);

                noteOnEvents.Add((loop: (int)onLoop, offset: onOffset, note: (byte)(note.NoteNumber + 12)));
                var offLoop   = (double)VstHost.SampleRate * (note.Start + note.Duration) / VstHost.BlockSize;
                var offOffset = (int)((offLoop - (int)offLoop) * VstHost.BlockSize);

                noteOffEvents.Add((loop: (int)offLoop, offset: offOffset, note: (byte)(note.NoteNumber + 12)));
            }

            var hasExportedAudio = false;

            for (var i = 0; i < 10; i++)
            {
                if (DoAudioWaveExport(plugin, tempFileName, noteOnEvents, noteOffEvents, initialDelay,
                                      preset.PreviewNotePlayer.MaxDuration))
                {
                    hasExportedAudio = true;
                    break;
                }
            }


            if (hasExportedAudio)
            {
                ConvertToOGG(tempFileName, preset.GetPreviewFilename());
            }
            else
            {
                plugin.Logger.Error("No audio data was returned by the plugin. Most likely it was still loading " +
                                    "the preset data; try to increase the audio preview pre-delay in the plugin " +
                                    "settings and try again");
            }

            File.Delete(tempFileName);
        }
コード例 #13
0
        protected override async Task ExecuteAsync(object parameter)
        {
            var pluginPresets = from item in _globalFrontendService.PresetExportList
                                group item by item.Plugin
                                into pluginGroup
                                let first = pluginGroup.First()
                                            select new
            {
                first.Plugin,
                Presets = pluginGroup.Select(gi => new { Preset = gi })
            };

            int totalPresets  = _globalFrontendService.PresetExportList.Count;
            int currentPreset = 0;

            _applicationService.StartApplicationOperation(this, "Exporting Presets",
                                                          totalPresets);
            var progress = _applicationService.GetApplicationProgress();

            await TaskHelper.Run(async() =>
            {
                var exportDirectory = _globalService.RuntimeConfiguration
                                      .NativeInstrumentsUserContentDirectory;

                if (!Directory.Exists(exportDirectory))
                {
                    LogTo.Warning($"Directory {exportDirectory} does not exist, using the default");
                }

                foreach (var pluginPreset in pluginPresets)
                {
                    Preset lastPreset = null;
                    try
                    {
                        await _presetDataPersisterService.OpenDatabase();

                        if (pluginPreset.Plugin.PresetParser == null)
                        {
                            _applicationService.AddApplicationOperationError(
                                $"Unable to update export presets for {pluginPreset.Plugin.PluginName} because it has no Preset Parser. Try to force-reload metadata for this plugin.");
                            continue;
                        }


                        using (var remotePluginInstance =
                                   _remoteVstService.GetRemotePluginInstance(pluginPreset.Plugin, false))
                        {
                            foreach (var preset in pluginPreset.Presets)
                            {
                                lastPreset = preset.Preset;
                                currentPreset++;
                                _applicationService.UpdateApplicationOperationStatus(
                                    currentPreset,
                                    $"Exporting {pluginPreset.Plugin.PluginName} - {preset.Preset.Metadata.PresetName}");

                                if (progress.CancellationToken.IsCancellationRequested)
                                {
                                    return;
                                }

                                var presetData = await _presetDataPersisterService.GetPresetData(preset.Preset);

                                if (preset.Preset.PresetBank == null)
                                {
                                    preset.Preset.PresetBank = preset.Preset.Plugin.RootBank;
                                    LogTo.Warning(
                                        $"Preset {preset.Preset.Metadata.PresetName} has no preset bank, using none.");
                                }

                                var presetExportInfo = new PresetExportInfo(preset.Preset)
                                {
                                    FolderMode           = _globalService.RuntimeConfiguration.FolderExportMode,
                                    OverwriteMode        = _globalService.RuntimeConfiguration.FileOverwriteMode,
                                    UserContentDirectory = exportDirectory
                                };

                                if (!presetExportInfo.CanExport())
                                {
                                    _applicationService.AddApplicationOperationError(
                                        $"Cannot export {preset.Preset.Plugin} -{preset.Preset.Metadata.PresetName}. " +
                                        $"Reason: {presetExportInfo.CannotExportReason}");
                                    continue;
                                }

                                pluginPreset.Plugin.PresetParser.PluginInstance = remotePluginInstance;

                                if (_globalService.RuntimeConfiguration.ExportWithAudioPreviews &&
                                    pluginPreset.Plugin.PluginType == Plugin.PluginTypes.Instrument)
                                {
                                    await remotePluginInstance.LoadPlugin().ConfigureAwait(false);
                                    pluginPreset.Plugin.PresetParser.OnPluginLoad();
                                    remotePluginInstance.SetChunk(presetData, false);

                                    remotePluginInstance.ExportNksAudioPreview(presetExportInfo, presetData,
                                                                               preset.Preset.Plugin.GetAudioPreviewDelay());
                                }

                                remotePluginInstance.ExportNks(presetExportInfo, presetData);


                                pluginPreset.Plugin.PresetParser.OnAfterPresetExport();
                                preset.Preset.LastExported = DateTime.Now;
                                preset.Preset.UpdateLastExportedMetadata();
                            }

                            if (remotePluginInstance.IsLoaded)
                            {
                                pluginPreset.Plugin.PresetParser.OnPluginUnload();
                            }

                            remotePluginInstance.UnloadPlugin();
                        }
                    }
                    catch (Exception e)
                    {
                        var errorMessage =
                            $"Unable to export presets for {pluginPreset.Plugin.PluginName} because of {e.GetType().FullName}: {e.Message}. ";

                        if (lastPreset != null)
                        {
                            errorMessage +=
                                $"The preset causing the error was: {lastPreset.Metadata.PresetName} in bank path {lastPreset.Metadata.BankPath}";
                        }

                        _applicationService.AddApplicationOperationError(
                            errorMessage
                            );
                        LogTo.Debug(e.StackTrace);
                    }

                    await _presetDataPersisterService.CloseDatabase();

                    _dataPersisterService.SavePresetsForPlugin(pluginPreset.Plugin);
                }
            });

            _applicationService.StopApplicationOperation("Export completed");
        }