Skip to content

Commit dfeb50d

Browse files
jmelovichkblaschke
authored andcommitted
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 dfeb50d

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

Diff for: src/RenderLoop.cpp

+64
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
RenderLoop::RenderLoop()
1416
: _audioCapture(Poco::Util::Application::instance().getSubsystem<AudioCapture>())
1517
, _projectMWrapper(Poco::Util::Application::instance().getSubsystem<ProjectMWrapper>())
@@ -103,6 +105,68 @@ void RenderLoop::PollEvents()
103105

104106
break;
105107

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

0 commit comments

Comments
 (0)