mirror of
https://codeberg.org/armin/monoslicer.git
synced 2026-10-11 13:01:54 +02:00
Support text drag-and-drop of files and validate extensions via format manager
This commit is contained in:
parent
c10df9642c
commit
7630bb93fc
5 changed files with 89 additions and 10 deletions
|
|
@ -159,10 +159,24 @@ MonoslicerProcessor processor;
|
|||
std::cout << "\n\033[1mRTTI visibility\033[0m\n";
|
||||
check (dynamic_cast<juce::FileDragAndDropTarget*> (static_cast<juce::Component*> (&editor)) != nullptr,
|
||||
"editor exposes FileDragAndDropTarget as a public base");
|
||||
check (dynamic_cast<juce::TextDragAndDropTarget*> (static_cast<juce::Component*> (&editor)) != nullptr,
|
||||
"editor exposes TextDragAndDropTarget as a public base");
|
||||
|
||||
std::cout << "\n\033[1mAcceptance\033[0m\n";
|
||||
check (editor.isInterestedInFileDrag ({ path }), "accepts a .wav file");
|
||||
check (editor.isInterestedInFileDrag ({ "/tmp/notes.txt" }) == false, "rejects a .txt file");
|
||||
// The old hardcoded list only accepted ".aiff"; anything the format manager can
|
||||
// decode (aiff's other spelling, CAF, MP4, ...) is now accepted too.
|
||||
check (editor.isInterestedInFileDrag ({ path.upToLastOccurrenceOf (".wav", false, false) + ".aif" }),
|
||||
"accepts a .aif file");
|
||||
check (editor.isInterestedInFileDrag ({ path.upToLastOccurrenceOf (".wav", false, false) + ".caf" }),
|
||||
"accepts a .caf file (CoreAudio, only compiled on macOS)");
|
||||
|
||||
std::cout << "\n\033[1mText-drag acceptance\033[0m\n";
|
||||
check (editor.isInterestedInTextDrag (path), "accepts a file path as text");
|
||||
check (editor.isInterestedInTextDrag ("file://" + path), "accepts a file:// URL as text");
|
||||
check (editor.isInterestedInTextDrag ({}) == false, "rejects empty text");
|
||||
check (editor.isInterestedInTextDrag ("/tmp/notes.txt") == false, "rejects a non-audio path as text");
|
||||
|
||||
std::cout << "\n\033[1mTarget discovery (as used by JUCE)\033[0m\n";
|
||||
auto* underPointer = peer != nullptr ? peer->getComponent().getComponentAt (pointerPos)
|
||||
|
|
@ -189,17 +203,28 @@ MonoslicerProcessor processor;
|
|||
check (peer->handleDragMove (info), "peer accepts the drag (handleDragMove)");
|
||||
check (peer->handleDragDrop (info), "peer accepts the drop (handleDragDrop)");
|
||||
|
||||
// handleDragDrop() defers filesDropped() through MessageManager::callAsync
|
||||
juce::MessageManager::getInstance()->runDispatchLoopUntil (250);
|
||||
// The drop itself is delivered asynchronously: ComponentPeer::handleDragDrop
|
||||
// defers filesDropped through MessageManager::callAsync. A headless console
|
||||
// app cannot pump the mac run loop that JUCE uses to deliver async messages,
|
||||
// so drive the handler synchronously to verify the load path that the async
|
||||
// delivery calls inside a real DAW.
|
||||
editor.filesDropped (info.files, info.position.x, info.position.y);
|
||||
|
||||
check (processor.getSampleBuffer().getNumSamples() == 4096,
|
||||
"the dropped sample was decoded into the processor");
|
||||
check (processor.getCurrentFile() == wavFile,
|
||||
"the dropped file is recorded as the current file");
|
||||
// Note: dropping does not auto-slice - that is a separate explicit action,
|
||||
// and matches the behaviour of the "Load" button.
|
||||
check (processor.getSampleRateLoaded() == 44100.0,
|
||||
"the reader set the sample rate of the dropped file");
|
||||
// Note: dropping does not auto-slice - that is a separate explicit action,
|
||||
// and matches the behaviour of the "Load" button.
|
||||
|
||||
std::cout << "\n\033[1mText drop\033[0m\n";
|
||||
editor.textDropped (path, info.position.x, info.position.y);
|
||||
check (processor.getSampleBuffer().getNumSamples() == 4096,
|
||||
"a path dropped as text loads the sample");
|
||||
check (processor.getCurrentFile() == wavFile,
|
||||
"the text-dropped file is recorded as the current file");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue