Skip to content

Commit b07782f

Browse files
committed
working preset drag/drop
- dragging a preset file loads that preset into your current playlist and skips to it - dragging a directory of presets will load all of them into the current playlist and skip to the first
1 parent df6bfb5 commit b07782f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/RenderLoop.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
#include <SDL2/SDL.h>
1212

13+
#include <filesystem>
14+
namespace fs = std::filesystem;
15+
1316
RenderLoop::RenderLoop()
1417
: _audioCapture(Poco::Util::Application::instance().getSubsystem<AudioCapture>())
1518
, _projectMWrapper(Poco::Util::Application::instance().getSubsystem<ProjectMWrapper>())
@@ -103,6 +106,56 @@ void RenderLoop::PollEvents()
103106

104107
break;
105108

109+
case SDL_DROPFILE: {
110+
char* droppedFilePath = event.drop.file;
111+
112+
bool shuffle = projectm_playlist_get_shuffle(_playlistHandle);
113+
if (shuffle) {
114+
projectm_playlist_set_shuffle(_playlistHandle, false);
115+
}
116+
117+
int index = projectm_playlist_get_position(_playlistHandle) + 1;
118+
119+
do {
120+
if (!fs::is_directory(droppedFilePath)) {
121+
Poco::Path droppedFileP(droppedFilePath);
122+
if (!fs::exists(droppedFilePath) || (droppedFileP.getExtension() != "milk" && droppedFileP.getExtension() != "prjm")) {
123+
std::string toastMessage = std::string("Invalid preset file: ") + droppedFilePath;
124+
Poco::NotificationCenter::defaultCenter().postNotification(new DisplayToastNotification(toastMessage));
125+
poco_information_f1(_logger, "%s", toastMessage);
126+
break; // exit the block and go to the shuffle check
127+
}
128+
129+
if (projectm_playlist_insert_preset(_playlistHandle, droppedFilePath, index, true)) {
130+
projectm_playlist_play_next(_playlistHandle, true);
131+
poco_information_f1(_logger, "Added preset: %s", std::string(droppedFilePath));
132+
// no need to toast single presets, as its obvious if a preset was loaded.
133+
}
134+
} else {
135+
uint32_t addedFilesCount = projectm_playlist_insert_path(_playlistHandle, droppedFilePath, index, true, true);
136+
if (addedFilesCount > 0) {
137+
std::string toastMessage = "Added " + std::to_string(addedFilesCount) + " presets from " + droppedFilePath;
138+
poco_information_f1(_logger, "%s", toastMessage);
139+
projectm_playlist_play_next(_playlistHandle, true);
140+
Poco::NotificationCenter::defaultCenter().postNotification(new DisplayToastNotification(toastMessage));
141+
142+
}else{
143+
std::string toastMessage = std::string("No presets found in: ") + droppedFilePath;
144+
Poco::NotificationCenter::defaultCenter().postNotification(new DisplayToastNotification(toastMessage));
145+
poco_information_f1(_logger, "%s", toastMessage);
146+
}
147+
}
148+
} while (false);
149+
150+
if (shuffle) {
151+
projectm_playlist_set_shuffle(_playlistHandle, true);
152+
}
153+
154+
SDL_free(droppedFilePath);
155+
break;
156+
}
157+
158+
106159
case SDL_QUIT:
107160
_wantsToQuit = true;
108161
break;

0 commit comments

Comments
 (0)