Skip to content

Commit 9d93ead

Browse files
jmelovichkblaschke
authored andcommitted
added drag/drop config settings
- added two new settings: 'skipToDropped' & 'droppedFolderOverride' to provide more user control over the drag & drop functionality.
1 parent dfeb50d commit 9d93ead

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

src/ProjectMSDLApplication.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ void ProjectMSDLApplication::initialize(Poco::Util::Application& self)
7676
{
7777
loadConfiguration(configFilePath.toString(), PRIO_DEFAULT);
7878
}
79-
8079
}
8180
}
8281
}
@@ -202,6 +201,14 @@ void ProjectMSDLApplication::defineOptions(Poco::Util::OptionSet& options)
202201
false, "<0/1>", true)
203202
.binding("projectM.shuffleEnabled", _commandLineOverrides));
204203

204+
options.addOption(Option("skipToDropped", "", "Skip to drag & dropped presets",
205+
false, "<0/1>", true)
206+
.binding("projectM.skipToDropped", _commandLineOverrides));
207+
208+
options.addOption(Option("droppedFolderOverride", "", "When dropping a folder, clear the playlist and add all presets from the folder.",
209+
false, "<0/1>", true)
210+
.binding("projectM.droppedFolderOverride", _commandLineOverrides));
211+
205212
options.addOption(Option("presetDuration", "", "Preset duration. Any number > 1, default 30.",
206213
false, "<number>", true)
207214
.binding("projectM.displayDuration", _commandLineOverrides));
@@ -273,4 +280,3 @@ void ProjectMSDLApplication::ListAudioDevices(POCO_UNUSED const std::string& nam
273280
{
274281
_commandLineOverrides->setBool("audio.listDevices", true);
275282
}
276-

src/RenderLoop.cpp

+31-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ RenderLoop::RenderLoop()
1919
, _projectMHandle(_projectMWrapper.ProjectM())
2020
, _playlistHandle(_projectMWrapper.Playlist())
2121
, _projectMGui(Poco::Util::Application::instance().getSubsystem<ProjectMGUI>())
22+
, _userConfig(ProjectMSDLApplication::instance().UserConfiguration())
2223
{
2324
}
2425

@@ -108,9 +109,18 @@ void RenderLoop::PollEvents()
108109
case SDL_DROPFILE: {
109110
char* droppedFilePath = event.drop.file;
110111

112+
// first we want to get the config settings that are relevant ehre
113+
// namely skipToDropped and droppedFolderOverride
114+
// we can get them from the projectMWrapper, in the _projectMConfigView available on it
115+
bool skipToDropped = _userConfig->getBool("projectM.skipToDropped", true);
116+
bool droppedFolderOverride = _userConfig->getBool("projectM.droppedFolderOverride", false);
117+
118+
111119
bool shuffle = projectm_playlist_get_shuffle(_playlistHandle);
112-
if (shuffle)
120+
if (shuffle && skipToDropped)
113121
{
122+
// if shuffle is enabled, we disable it temporarily, so the dropped preset is played next
123+
// if skipToDropped is false, we also keep shuffle enabled, as it doesn't matter since the current preset is unaffected
114124
projectm_playlist_set_shuffle(_playlistHandle, false);
115125
}
116126

@@ -133,19 +143,36 @@ void RenderLoop::PollEvents()
133143

134144
if (projectm_playlist_insert_preset(_playlistHandle, droppedFilePath, index, true))
135145
{
136-
projectm_playlist_play_next(_playlistHandle, true);
146+
if (skipToDropped)
147+
{
148+
projectm_playlist_play_next(_playlistHandle, true);
149+
}
137150
poco_information_f1(_logger, "Added preset: %s", std::string(droppedFilePath));
138151
// no need to toast single presets, as its obvious if a preset was loaded.
139152
}
140153
}
141154
else
142155
{
156+
// handle dropped directory
157+
158+
// if droppedFolderOverride is enabled, we clear the playlist first
159+
// current edge case: if the dropped directory is invalid or contains no presets, then it still clears the playlist
160+
if (droppedFolderOverride)
161+
{
162+
projectm_playlist_clear(_playlistHandle);
163+
index = 0;
164+
}
165+
143166
uint32_t addedFilesCount = projectm_playlist_insert_path(_playlistHandle, droppedFilePath, index, true, true);
144167
if (addedFilesCount > 0)
145168
{
146169
std::string toastMessage = "Added " + std::to_string(addedFilesCount) + " presets from " + droppedFilePath;
147170
poco_information_f1(_logger, "%s", toastMessage);
148-
projectm_playlist_play_next(_playlistHandle, true);
171+
if (skipToDropped || droppedFolderOverride)
172+
{
173+
// if skip to dropped is true, or if a folder was dropped and it overrode the playlist, we skip to the next preset
174+
projectm_playlist_play_next(_playlistHandle, true);
175+
}
149176
Poco::NotificationCenter::defaultCenter().postNotification(new DisplayToastNotification(toastMessage));
150177
}
151178
else
@@ -157,7 +184,7 @@ void RenderLoop::PollEvents()
157184
}
158185
} while (false);
159186

160-
if (shuffle)
187+
if (shuffle && skipToDropped)
161188
{
162189
projectm_playlist_set_shuffle(_playlistHandle, true);
163190
}

src/RenderLoop.h

+2
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,7 @@ class RenderLoop
8787

8888
ModifierKeyStates _keyStates; //!< Current "pressed" states of modifier keys
8989

90+
Poco::AutoPtr<Poco::Util::AbstractConfiguration> _userConfig; //!< View of the "projectM" configuration subkey in the "user" configuration.
91+
9092
Poco::Logger& _logger{Poco::Logger::get("RenderLoop")}; //!< The class logger.
9193
};

src/gui/SettingsWindow.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ void SettingsWindow::DrawProjectMSettingsTab()
105105
LabelWithTooltip("Shuffle Presets", "Selects presets randomly from the current playlist.");
106106
BooleanSetting("projectM.shuffleEnabled", true);
107107

108+
ImGui::TableNextRow();
109+
LabelWithTooltip("Skip To Dropped Presets", "If enabled, will skip to the new presets when preset(s) are dropped onto the window and added to the playlist");
110+
BooleanSetting("projectM.skipToDropped", true);
111+
112+
ImGui::TableNextRow();
113+
LabelWithTooltip("Dropped Folder Overrides Playlist", "When dropping a folder, clear the playlist and add all presets from the folder.");
114+
BooleanSetting("projectM.droppedFolderOverride", false);
115+
108116
ImGui::TableNextRow();
109117
LabelWithTooltip("Preset Display Duration", "Time in seconds a preset will be displayed before it's switched.");
110118
DoubleSetting("projectM.displayDuration", 30.0, 1.0, 240.0);

0 commit comments

Comments
 (0)