Esempio n. 1
0
 private string MakePreviewRelative(PresetExportInfo presetExportInfo, bool wav = false)
 {
     return(presetExportInfo.GetPreviewFilename(wav).Replace(presetExportInfo.UserContentDirectory + @"\", ""));
 }
Esempio n. 2
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);
        }