10
10
11
11
#include < SDL2/SDL.h>
12
12
13
+ #include " ProjectMSDLApplication.h"
14
+
13
15
#include < filesystem>
14
16
namespace fs = std::filesystem;
15
17
@@ -20,6 +22,7 @@ RenderLoop::RenderLoop()
20
22
, _projectMHandle(_projectMWrapper.ProjectM())
21
23
, _playlistHandle(_projectMWrapper.Playlist())
22
24
, _projectMGui(Poco::Util::Application::instance().getSubsystem<ProjectMGUI>())
25
+ , _userConfig(ProjectMSDLApplication::instance().UserConfiguration())
23
26
{
24
27
}
25
28
@@ -109,15 +112,25 @@ void RenderLoop::PollEvents()
109
112
case SDL_DROPFILE: {
110
113
char * droppedFilePath = event.drop .file ;
111
114
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
+
112
122
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
114
126
projectm_playlist_set_shuffle (_playlistHandle, false );
115
127
}
116
128
117
129
int index = projectm_playlist_get_position (_playlistHandle) + 1 ;
118
130
119
131
do {
120
132
if (!fs::is_directory (droppedFilePath)) {
133
+ // handle dropped preset file
121
134
Poco::Path droppedFileP (droppedFilePath);
122
135
if (!fs::exists (droppedFilePath) || (droppedFileP.getExtension () != " milk" && droppedFileP.getExtension () != " prjm" )) {
123
136
std::string toastMessage = std::string (" Invalid preset file: " ) + droppedFilePath;
@@ -127,16 +140,30 @@ void RenderLoop::PollEvents()
127
140
}
128
141
129
142
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
+ }
131
146
poco_information_f1 (_logger, " Added preset: %s" , std::string (droppedFilePath));
132
147
// no need to toast single presets, as its obvious if a preset was loaded.
133
148
}
134
149
} 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
+
135
159
uint32_t addedFilesCount = projectm_playlist_insert_path (_playlistHandle, droppedFilePath, index, true , true );
136
160
if (addedFilesCount > 0 ) {
137
161
std::string toastMessage = " Added " + std::to_string (addedFilesCount) + " presets from " + droppedFilePath;
138
162
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
+ }
140
167
Poco::NotificationCenter::defaultCenter ().postNotification (new DisplayToastNotification (toastMessage));
141
168
142
169
}else {
@@ -147,7 +174,7 @@ void RenderLoop::PollEvents()
147
174
}
148
175
} while (false );
149
176
150
- if (shuffle) {
177
+ if (shuffle && skipToDropped ) {
151
178
projectm_playlist_set_shuffle (_playlistHandle, true );
152
179
}
153
180
0 commit comments