Implementing drag and drop triggers
Monday 3 August 2020
In order to implement drag and drop, as you might imagine, there's another abstract class we have to deal with. It's called FileDragAndDropTarget.
1. We need to go to DeckGUI.h and add this to our inheritances.
class DeckGUI : public juce::Component,
public juce::Button::Listener,
public juce::Slider::Listener,
public juce::FileDragAndDropTarget
2. In public: add the functions we need:
bool isInterestedInDragAndDrop(const juce::StringArray &files) override;
void filesDropped(const juce::StringArray &files, int x, int y) override;
3. We have now defined our functions and the next step is to go and implement them. At the bottom of DeckGUI.cpp we add:
bool DeckGUI::isInterestedInFileDrag (const juce::StringArray &files)
{
return true;
}
void DeckGUI::filesDropped (const juce::StringArray &files, int x, int y)
{
std::cout << "DeckGUI::filesDropped" << std::endl;
if (files.size() == 1)
{
player->loadURL(juce::URL{ juce::File{files[0]} });
}
}
And that seems to work!
More posts in cpp
- Add a component ID and converting between ints and strings
- Implement a play button and add a listener
- Implement paintRowBackground and paintCell
- Add a vector to store a list of files
- Add a TableListBox
- Create a PlaylistComponent in the Projucer project
- Threads
- Implement a timer
- Add getPosition and setPosition functions
- Refactor DJAudioPlayer to use app-scope formatManager
- Draw the thumbnail
- Hook up the load button to trigger the AudioThumbnail load
- The AudioThumbnail class in the API
- Creating a new component - WaveformDisplay
- Implementing drag and drop triggers
- Use a MixerAudioSource to play more than one file at a time
- Implement the listener interfaces to DeckGUI
- Creating a DeckGUI class
- setPosition control
- Implementing setGain and setSpeed
- Add audio playback functionality
- Writing the DJAudioPlayer class
- Creating a new JUCE class with Projucer
- Refactoring our code
- Using ResamplingAudioPlayer to implement variable speed playback
- Add stop, start and volume functionality
- Add a file chooser
- Audio file playback in JUCE
- Realtime sound synthesis in JUCE
- Adding a slider listener
- Introduction to event listeners
- Macros
- Inheritance
- Adding a GUI widget to the JUCE app
- Introduction to JUCE