|
| 1 | +/* |
| 2 | + // Copyright (c) 2026 Timothy Schoen and Wasted Audio |
| 3 | + // For information on usage and redistribution, and for a DISCLAIMER OF ALL |
| 4 | + // WARRANTIES, see the file, "LICENSE.txt," in this distribution. |
| 5 | + */ |
| 6 | +#pragma once |
| 7 | + |
| 8 | +class UnityExporter final : public ExporterBase { |
| 9 | +public: |
| 10 | + UnityExporter(PluginEditor* editor, ExportingProgressView* exportingView) |
| 11 | + : ExporterBase(editor, exportingView) |
| 12 | + { |
| 13 | + } |
| 14 | + |
| 15 | + void getState(DynamicObject::Ptr globalState) override |
| 16 | + { |
| 17 | + auto* state = new DynamicObject(); |
| 18 | + state->setProperty("input_patch_value", getValue<String>(inputPatchValue)); |
| 19 | + state->setProperty("project_name_value", getValue<String>(projectNameValue)); |
| 20 | + state->setProperty("project_copyright_value", getValue<String>(projectCopyrightValue)); |
| 21 | + globalState->setProperty("unity", state); |
| 22 | + } |
| 23 | + |
| 24 | + void setState(DynamicObject::Ptr globalState) override |
| 25 | + { |
| 26 | + auto const state = globalState->getProperty("unity").getDynamicObject(); |
| 27 | + if (!state) |
| 28 | + return; |
| 29 | + inputPatchValue = state->getProperty("input_patch_value"); |
| 30 | + projectNameValue = state->getProperty("project_name_value"); |
| 31 | + projectCopyrightValue = state->getProperty("project_copyright_value"); |
| 32 | + } |
| 33 | + |
| 34 | + bool performExport(String const& pdPatch, String const& outdir, String const& name, String const& copyright, StringArray const& searchPaths) override |
| 35 | + { |
| 36 | + exportingView->showState(ExportingProgressView::Exporting); |
| 37 | + |
| 38 | + auto const heavyPath = pathToString(heavyExecutable); |
| 39 | + |
| 40 | + StringArray args = { heavyPath.quoted(), pdPatch.quoted(), "-o", outdir.quoted() }; |
| 41 | + |
| 42 | + args.add("-n" + name); |
| 43 | + |
| 44 | + if (copyright.isNotEmpty()) { |
| 45 | + args.add("--copyright"); |
| 46 | + args.add(copyright.quoted()); |
| 47 | + } |
| 48 | + |
| 49 | + args.add("-v"); |
| 50 | + args.add("-gunity"); |
| 51 | + |
| 52 | + args.add("-p"); |
| 53 | + for (auto& path : searchPaths) { |
| 54 | + args.add(path); |
| 55 | + } |
| 56 | + |
| 57 | + if (shouldQuit) |
| 58 | + return true; |
| 59 | + |
| 60 | + auto const command = args.joinIntoString(" "); |
| 61 | + startShellScript(command); |
| 62 | + |
| 63 | + waitForProcessToFinish(-1); |
| 64 | + exportingView->flushConsole(); |
| 65 | + |
| 66 | + if (shouldQuit) |
| 67 | + return true; |
| 68 | + |
| 69 | + auto const outputFile = File(outdir); |
| 70 | + outputFile.getChildFile("ir").deleteRecursively(); |
| 71 | + outputFile.getChildFile("hv").deleteRecursively(); |
| 72 | + |
| 73 | + // Delay to get correct exit code |
| 74 | + Time::waitForMillisecondCounter(Time::getMillisecondCounter() + 300); |
| 75 | + |
| 76 | + return getExitCode(); |
| 77 | + } |
| 78 | +}; |
0 commit comments