Skip to content

Commit cce6224

Browse files
committed
added drag/drop config settings
- added two new settings: 'skipToDropped' & 'droppedFolderOverride' to provide more user control over the drag & drop functionality.
1 parent b07782f commit cce6224

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

src/ProjectMSDLApplication.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ void ProjectMSDLApplication::defineOptions(Poco::Util::OptionSet& options)
202202
false, "<0/1>", true)
203203
.binding("projectM.shuffleEnabled", _commandLineOverrides));
204204

205+
options.addOption(Option("skipToDropped", "", "Skip to drag & dropped presets",
206+
false, "<0/1>", true)
207+
.binding("projectM.skipToDropped", _commandLineOverrides));
208+
209+
options.addOption(Option("droppedFolderOverride", "", "When dropping a folder, clear the playlist and add all presets from the folder.",
210+
false, "<0/1>", true)
211+
.binding("projectM.droppedFolderOverride", _commandLineOverrides));
212+
205213
options.addOption(Option("presetDuration", "", "Preset duration. Any number > 1, default 30.",
206214
false, "<number>", true)
207215
.binding("projectM.displayDuration", _commandLineOverrides));

src/RenderLoop.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include <SDL2/SDL.h>
1212

13+
#include "ProjectMSDLApplication.h"
14+
1315
#include <filesystem>
1416
namespace fs = std::filesystem;
1517

@@ -20,6 +22,7 @@ RenderLoop::RenderLoop()
2022
, _projectMHandle(_projectMWrapper.ProjectM())
2123
, _playlistHandle(_projectMWrapper.Playlist())
2224
, _projectMGui(Poco::Util::Application::instance().getSubsystem<ProjectMGUI>())
25+
, _userConfig(ProjectMSDLApplication::instance().UserConfiguration())
2326
{
2427
}
2528

@@ -109,15 +112,25 @@ void RenderLoop::PollEvents()
109112
case SDL_DROPFILE: {
110113
char* droppedFilePath = event.drop.file;
111114

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

117129
int index = projectm_playlist_get_position(_playlistHandle) + 1;
118130

119131
do {
120132
if (!fs::is_directory(droppedFilePath)) {
133+
// handle dropped preset file
121134
Poco::Path droppedFileP(droppedFilePath);
122135
if (!fs::exists(droppedFilePath) || (droppedFileP.getExtension() != "milk" && droppedFileP.getExtension() != "prjm")) {
123136
std::string toastMessage = std::string("Invalid preset file: ") + droppedFilePath;
@@ -127,16 +140,30 @@ void RenderLoop::PollEvents()
127140
}
128141

129142
if (projectm_playlist_insert_preset(_playlistHandle, droppedFilePath, index, true)) {
130-
projectm_playlist_play_next(_playlistHandle, true);
143+
if(skipToDropped){
144+
projectm_playlist_play_next(_playlistHandle, true);
145+
}
131146
poco_information_f1(_logger, "Added preset: %s", std::string(droppedFilePath));
132147
// no need to toast single presets, as its obvious if a preset was loaded.
133148
}
134149
} else {
150+
// handle dropped directory
151+
152+
// if droppedFolderOverride is enabled, we clear the playlist first
153+
// current edge case: if the dropped directory is invalid or contains no presets, then it still clears the playlist
154+
if (droppedFolderOverride) {
155+
projectm_playlist_clear(_playlistHandle);
156+
index = 0;
157+
}
158+
135159
uint32_t addedFilesCount = projectm_playlist_insert_path(_playlistHandle, droppedFilePath, index, true, true);
136160
if (addedFilesCount > 0) {
137161
std::string toastMessage = "Added " + std::to_string(addedFilesCount) + " presets from " + droppedFilePath;
138162
poco_information_f1(_logger, "%s", toastMessage);
139-
projectm_playlist_play_next(_playlistHandle, true);
163+
if(skipToDropped || droppedFolderOverride){
164+
// if skip to dropped is true, or if a folder was dropped and it overrode the playlist, we skip to the next preset
165+
projectm_playlist_play_next(_playlistHandle, true);
166+
}
140167
Poco::NotificationCenter::defaultCenter().postNotification(new DisplayToastNotification(toastMessage));
141168

142169
}else{
@@ -147,7 +174,7 @@ void RenderLoop::PollEvents()
147174
}
148175
} while (false);
149176

150-
if (shuffle) {
177+
if (shuffle && skipToDropped) {
151178
projectm_playlist_set_shuffle(_playlistHandle, true);
152179
}
153180

src/RenderLoop.h

Lines changed: 2 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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)