1010
1111#include < SDL2/SDL.h>
1212
13+ #include " ProjectMSDLApplication.h"
14+
1315#include < filesystem>
1416namespace 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
0 commit comments