Skip to content

Commit 0c08748

Browse files
committed
enable embedding of presets during build
add EMBED_PRESETS option to cmake add -e option to build_plugins.sh
1 parent da1f3af commit 0c08748

File tree

8 files changed

+99
-57
lines changed

8 files changed

+99
-57
lines changed

CMakeLists.txt

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ function(add_osccontrol_target TARGET FORMATS)
1818
# EDITOR_WANTS_KEYBOARD_FOCUS TRUE/FALSE # Does the editor need keyboard focus?
1919
COPY_PLUGIN_AFTER_BUILD FALSE # Should the plugin be installed to a default location after building?
2020
PLUGIN_MANUFACTURER_CODE drLt # A four-character manufacturer id with at least one upper-case character
21-
# PLUGIN_CODE oscL # A unique four-character plugin id with at least one upper-case character
22-
PLUGIN_NAME ${TARGET}
23-
FORMATS ${FORMATS} # The formats to build. Other valid formats are: AAX Unity VST AU AUv3
24-
PRODUCT_NAME ${TARGET}) # The name of the final executable, which can differ from the target name
21+
# PLUGIN_CODE oscL # A unique four-character plugin id with at least one upper-case character
22+
PLUGIN_NAME "${TARGET}"
23+
FORMATS "${FORMATS}" # The formats to build. Other valid formats are: AAX Unity VST AU AUv3
24+
PRODUCT_NAME "${TARGET}") # The name of the final executable, which can differ from the target name
2525
endfunction()
2626

2727
function(configure_osccontrol_target TARGET)
@@ -56,15 +56,26 @@ function(configure_osccontrol_target TARGET)
5656
Source/UIComponentFactory.h
5757
)
5858

59-
target_compile_definitions(${TARGET}
60-
PUBLIC
59+
target_compile_definitions(${TARGET} PUBLIC
6160
# JUCE_WEB_BROWSER and JUCE_USE_CURL would be on by default, but you might not need them.
6261
JUCE_WEB_BROWSER=0 # If you remove this, add `NEEDS_WEB_BROWSER TRUE` to the `juce_add_plugin` call
6362
JUCE_USE_CURL=0 # If you remove this, add `NEEDS_CURL TRUE` to the `juce_add_plugin` call
6463
JUCE_VST3_CAN_REPLACE_VST2=0
6564
JUCE_MODAL_LOOPS_PERMITTED=1 # allow modal loops for now to enable file chooser dialog
6665
YAML_CPP_STATIC_DEFINE=1
66+
)
67+
68+
if(EMBED_PRESETS AND NOT "${TARGET}" STREQUAL "osccontrol-light")
69+
STRING(REGEX REPLACE "^osc-" "" PRESET ${TARGET})
70+
target_compile_definitions("${TARGET}" PUBLIC EMBED_PRESET)
71+
juce_add_binary_data("${TARGET}-data"
72+
HEADER_NAME "EmbeddedPreset.h"
73+
NAMESPACE "osccontrol_embedded_preset"
74+
SOURCES "Presets/${PRESET}.yaml"
6775
)
76+
set_target_properties("${TARGET}-data" PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
77+
target_link_libraries(${TARGET} PRIVATE "${TARGET}-data")
78+
endif()
6879

6980
target_link_libraries(${TARGET} PRIVATE
7081
osccontrol-light-data
@@ -87,15 +98,16 @@ juce_add_binary_data(osccontrol-light-data SOURCES
8798
set_target_properties(osccontrol-light-data PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
8899

89100
# we always build the interactive gui version of the plugin as VST3 and standalone application
90-
message("creating build target for osccontrol-light standalone application")
91-
message("creating build target for osccontrol-light VST3 plugin")
101+
message("creating build target for osccontrol-light (Standalone)")
102+
message("creating build target for osccontrol-light (VST3)")
92103
add_osccontrol_target(osccontrol-light "Standalone;VST3")
93104
configure_osccontrol_target(osccontrol-light)
94105

95-
set(PRESET_NAMES "" CACHE STRING "list of presets for which a plugin is built")
96-
foreach(PRESET_NAME ${PRESET_NAMES})
97-
message("creating build target for ${PRESET_NAME} preset VST3 plugin")
98-
set(PRESET_TARGET "osc-${PRESET_NAME}")
106+
set(PRESETS "" CACHE STRING "list of presets for which a plugin is built")
107+
set(EMBED_PRESETS "" CACHE BOOL "embed preset definition at build time")
108+
foreach(PRESET ${PRESETS})
109+
message("creating build target for ${PRESET} preset (VST3)")
110+
set(PRESET_TARGET "osc-${PRESET}")
99111
add_osccontrol_target(${PRESET_TARGET} "VST3")
100112
configure_osccontrol_target(${PRESET_TARGET})
101113
endforeach()

Source/PluginProcessor.cpp

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
1919
*/
2020

21+
#include "BinaryData.h"
22+
#ifdef EMBED_PRESET
23+
#include "EmbeddedPreset.h"
24+
#endif
25+
26+
2127
#include "PresetParser.h"
2228

2329
#include "ControlElementHost.h"
@@ -41,42 +47,39 @@ OSCControlAudioProcessor() :
4147
filenamePlugin = filePlugin.getFileNameWithoutExtension();
4248
auto filenameLog = filenamePlugin + ".log";
4349

50+
namePlugin = filenamePlugin;
51+
4452
fileLogger = std::make_unique<FileLogger>
4553
(filePlugin.getParentDirectory().getChildFile(filenameLog),
4654
"osccontrol-light debug log", 0);
4755

4856
Logger::setCurrentLogger(fileLogger.get());
49-
57+
5058
Logger::writeToLog(filePlugin.getFullPathName());
5159
Logger::writeToLog(filenamePlugin);
5260

5361
auto pathPreset =
5462
SystemStats::getEnvironmentVariable("OSCCONTROL_PRESET_PATH", "");
5563
dirPreset = File (pathPreset);
5664

57-
if (filenamePlugin != "osccontrol-light") {
58-
auto presetToLoad =
59-
filenamePlugin.fromFirstOccurrenceOf
60-
("osc", false, false).trimCharactersAtStart("-");
61-
62-
if (presetToLoad.isNotEmpty()) {
63-
Logger::writeToLog("presetToLoad: " + presetToLoad);
64-
namePlugin = filenamePlugin;
65-
66-
if (pathPreset == "") {
67-
AlertWindow::showMessageBox
68-
(AlertWindow::AlertIconType::WarningIcon,
69-
String("Error loading osccontrol-light with preset: ") + presetToLoad,
70-
"When running osccontrol-light in headless mode "
71-
"for DAW integration, make sure that "
72-
"OSCCONTROL_PRESET_PATH is set properly in "
73-
"the environment!"); // TODO freak out!!
74-
}
65+
auto presetToLoad = namePlugin.fromFirstOccurrenceOf
66+
("osc-", false, false).trimCharactersAtStart("-");
67+
Logger::writeToLog("presetToLoad: " + presetToLoad);
68+
69+
if (presetToLoad != "osccontrol-light" && presetToLoad.isNotEmpty()) {
70+
if (!dirPreset.exists()) {
71+
auto message =
72+
String("Error loading osccontrol-light with preset: ") + presetToLoad +
73+
"When running osccontrol-light in headless mode "
74+
"for DAW integration, make sure that "
75+
"OSCCONTROL_PRESET_PATH is set properly in "
76+
"the environment!";
7577

76-
auto presetFile = locatePresetFile(presetToLoad);
77-
hasUserInterface = false;
78-
initializeHeadless(presetFile);
78+
throw std::runtime_error (message.toStdString ());
7979
}
80+
81+
hasUserInterface = false;
82+
initializeHeadless(presetToLoad);
8083
}
8184
}
8285

@@ -90,7 +93,7 @@ OSCControlAudioProcessor::
9093
File
9194
OSCControlAudioProcessor::
9295
locatePresetFile
93-
(String namePreset)
96+
(String const & namePreset)
9497
{
9598
auto filenamePreset = namePreset + ".yaml";
9699
auto files = dirPreset.findChildFiles
@@ -109,11 +112,22 @@ locatePresetFile
109112
void
110113
OSCControlAudioProcessor::
111114
initializeHeadless
112-
(File filePreset)
115+
(String const & namePreset)
113116
{
114117
Logger::writeToLog("initializeHeadless");
115118

116-
PresetParser preset (filePreset);
119+
#ifdef EMBED_PRESET
120+
int sourceSize = 0;
121+
const void * sourceData =
122+
osccontrol_embedded_preset::getNamedResource(
123+
osccontrol_embedded_preset::namedResourceList[0], sourceSize);
124+
MemoryInputStream inputStream(sourceData, sourceSize, false);
125+
#else
126+
auto presetFile = locatePresetFile(namePreset);
127+
FileInputStream inputStream(presetFile);
128+
#endif
129+
130+
PresetParser preset (inputStream);
117131

118132
oscSender = std::make_unique<OSCSender> ();
119133
oscSender->connect (preset.getHost (), preset.getPort ());

Source/PluginProcessor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class OSCControlAudioProcessor :
3535
OSCControlAudioProcessor();
3636
~OSCControlAudioProcessor();
3737

38-
File locatePresetFile(String namePreset);
39-
void initializeHeadless(File filePreset);
38+
File locatePresetFile(String const & namePreset);
39+
void initializeHeadless(String const & namePreset);
4040

4141
void prepareToPlay (double sampleRate, int samplesPerBlock) override;
4242
void releaseResources() override;

Source/PresetPage.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ PresetPage::
4545

4646
void
4747
PresetPage::
48-
loadFromFile
49-
(File filePreset)
48+
load
49+
(InputStream & inputStream)
5050
{
51-
PresetParser preset (filePreset);
52-
auto presetPath = filePreset.getFullPathName ();
51+
PresetParser preset (inputStream);
5352

5453
host = preset.getHost ();
5554
port = preset.getPort ();
@@ -77,6 +76,16 @@ loadFromFile
7776
container->setBounds (areaContainer);
7877
}
7978

79+
void
80+
PresetPage::
81+
loadFromFile
82+
(File const & file)
83+
{
84+
FileInputStream inputStream(file);
85+
load(inputStream);
86+
}
87+
88+
8089
Value &
8190
PresetPage::
8291
getHostValue()

Source/PresetPage.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class PresetPage :
3333
PresetPage ();
3434
~PresetPage ();
3535

36-
void loadFromFile (File filePreset);
36+
void load (InputStream & inputStream);
37+
void loadFromFile (File const & file);
3738

3839
Value & getHostValue ();
3940
Value & getPortValue ();

Source/PresetParser.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,18 @@ PresetParser::mapTypeNames =
3232

3333
PresetParser::
3434
PresetParser
35-
(File filePreset)
35+
(InputStream & inputStream)
3636
{
37-
auto pathPreset = filePreset.getFullPathName().toStdString();
3837
try {
39-
config = YAML::LoadFile(pathPreset);
38+
config = YAML::Load(inputStream.readString().toStdString());
4039
}
4140
catch (YAML::BadFile &e) {
42-
std::string message = "Unable to load config: " + pathPreset;
41+
std::string message = "Could not parse preset";
4342
throw std::runtime_error(message);
4443
}
4544

4645
if(config.IsNull()) {
47-
std::string message = "Empty config: " + pathPreset;
46+
std::string message = "Could not parse preset";
4847
throw std::runtime_error(message);
4948
}
5049
}

Source/PresetParser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class PresetParser
3030
{
3131
public:
3232

33-
PresetParser(File filePreset);
33+
PresetParser(InputStream & inputStream);
3434

3535
String getHost() const;
3636
int getPort() const;

build_plugins.sh

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
function print_usage {
4-
printf "Usage: %s: [-j <jobs>] [-v] [<preset> ...]\n" $0
4+
printf "Usage: %s: [-j <jobs>] [-v] [-e] [<preset> ...]\n" $0
55
echo ""
66
echo "Build the osccontrol plugin."
77
echo ""
@@ -13,12 +13,14 @@ function print_usage {
1313
echo "Options:"
1414
echo "<preset> ...: list of preset names separated with spaces"
1515
echo "-j<jobs>: run build in parallel with <jobs> threads"
16-
echo "-v: print cmake progress output"
16+
echo "-v: verbosely print cmake output"
17+
echo "-e: embed presets during build"
1718
}
1819

1920
JOBS=1
2021
VERBOSE=0
21-
while getopts ":hvj:" opt; do
22+
EMBED=""
23+
while getopts ":hvej:" opt; do
2224
case ${opt} in
2325
\? )
2426
echo "Invalid option: $OPTARG" 1>&2
@@ -46,20 +48,25 @@ while getopts ":hvj:" opt; do
4648
v)
4749
VERBOSE=1
4850
;;
51+
e)
52+
EMBED="-DEMBED_PRESETS=ON"
53+
;;
4954
esac
5055
done
5156
shift $((OPTIND -1))
5257

53-
PRESET_NAMES=""
58+
PRESETS=""
5459
for preset in "$@"
5560
do
56-
PRESET_NAMES="$PRESET_NAMES;$preset"
61+
PRESETS="$PRESETS;$preset"
5762
done
5863

5964
echo "creating cmake config in 'build' directory"
6065
mkdir -p build ; cd build
61-
echo "cmake -DPRESET_NAMES=$PRESET_NAMES .."
62-
cmake -DPRESET_NAMES=$PRESET_NAMES ..
66+
67+
COMMAND="cmake -DPRESETS=$PRESETS $EMBED .."
68+
echo $COMMAND
69+
$COMMAND
6370

6471
echo "building osccontrol plugins... "
6572
if [ "$VERBOSE" -ne 0 ] ; then

0 commit comments

Comments
 (0)