Vital
Loading...
Searching...
No Matches
audio_file_drop_source.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4
5#include <climits>
6
19class AudioFileDropSource : public FileDragAndDropTarget {
20public:
26 class Listener {
27 public:
28 virtual ~Listener() { }
29
35 virtual void audioFileLoaded(const File& file) = 0;
36 };
37
42 format_manager_.registerBasicFormats();
43 }
44
51 bool isInterestedInFileDrag(const StringArray& files) override {
52 if (files.size() != 1)
53 return false;
54
55 String file = files[0];
56 StringArray wildcards;
57 wildcards.addTokens(getExtensions(), ";", "\"");
58 for (const String& wildcard : wildcards) {
59 if (file.matchesWildcard(wildcard, true))
60 return true;
61 }
62 return false;
63 }
64
74 void filesDropped(const StringArray& files, int x, int y) override {
75 if (files.size() == 0)
76 return;
77
78 File file(files[0]);
79 audioFileLoaded(file);
80 for (Listener* listener : listeners_)
81 listener->audioFileLoaded(file);
82 }
83
89 virtual void audioFileLoaded(const File& file) = 0;
90
96 void addListener(Listener* listener) { listeners_.push_back(listener); }
97
103 String getExtensions() { return format_manager_.getWildcardForAllFormats(); }
104
110 AudioFormatManager& formatManager() { return format_manager_; }
111
112protected:
113 AudioFormatManager format_manager_;
114
115private:
116 std::vector<Listener*> listeners_;
117
118 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(AudioFileDropSource)
119};
A listener interface for classes interested in receiving audio file load events.
Definition audio_file_drop_source.h:26
virtual void audioFileLoaded(const File &file)=0
Called when an audio file is successfully dropped and recognized.
virtual ~Listener()
Definition audio_file_drop_source.h:28
A helper class for handling drag-and-drop of audio files into a JUCE component.
Definition audio_file_drop_source.h:19
String getExtensions()
Gets a wildcard pattern representing all supported audio formats.
Definition audio_file_drop_source.h:103
virtual void audioFileLoaded(const File &file)=0
Called internally when a recognized audio file is dropped. Must be implemented by subclasses.
void filesDropped(const StringArray &files, int x, int y) override
Called when files are dropped onto the component.
Definition audio_file_drop_source.h:74
bool isInterestedInFileDrag(const StringArray &files) override
Checks if the drag operation includes exactly one file and if it matches supported audio formats.
Definition audio_file_drop_source.h:51
void addListener(Listener *listener)
Adds a listener to receive audio file load notifications.
Definition audio_file_drop_source.h:96
AudioFileDropSource()
Constructs an AudioFileDropSource and registers basic audio formats.
Definition audio_file_drop_source.h:41
AudioFormatManager & formatManager()
Provides access to the underlying AudioFormatManager.
Definition audio_file_drop_source.h:110
AudioFormatManager format_manager_
Manages and recognizes different audio file formats.
Definition audio_file_drop_source.h:113