tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_SamplerPlugin.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
14class SamplerPlugin : public Plugin,
15 private juce::AsyncUpdater
16{
17public:
19 ~SamplerPlugin() override;
20
21 //==============================================================================
22 int getNumSounds() const;
23 juce::String getSoundName (int index) const;
24 void setSoundName (int index, const juce::String& name);
25 AudioFile getSoundFile (int index) const;
26 juce::String getSoundMedia (int index) const;
27 int getKeyNote (int index) const;
28 int getMinKey (int index) const;
29 int getMaxKey (int index) const;
30 float getSoundGainDb (int index) const;
31 float getSoundPan (int index) const;
32 bool isSoundOpenEnded (int index) const;
33 double getSoundStartTime (int index) const;
34 double getSoundLength (int index) const;
35 void setSoundExcerpt (int index, double start, double length);
36
37 // returns an error
38 juce::String addSound (const juce::String& sourcePathOrProjectID, const juce::String& name,
39 double startTime, double length, float gainDb);
40 void removeSound (int index);
41 void setSoundParams (int index, int keyNote, int minNote, int maxNote);
42 void setSoundGains (int index, float gainDb, float pan);
43 void setSoundOpenEnded (int index, bool isOpenEnded);
44 void setSoundMedia (int index, const juce::String& sourcePathOrProjectID);
45
46 void playNotes (const juce::BigInteger& keysDown);
47 void allNotesOff();
48
49 //==============================================================================
50 static const char* getPluginName() { return NEEDS_TRANS("Sampler"); }
51 static const char* xmlTypeName;
52
53 juce::String getName() const override { return TRANS("Sampler"); }
54 juce::String getPluginType() override { return xmlTypeName; }
55 juce::String getShortName (int) override { return "Smplr"; }
56 juce::String getSelectableDescription() override { return TRANS("Sampler"); }
57 bool isSynth() override { return true; }
58 bool needsConstantBufferSize() override { return false; }
59
60 int getNumOutputChannelsGivenInputs (int numInputChannels) override { return juce::jmin (numInputChannels, 2); }
61 void initialise (const PluginInitialisationInfo&) override;
62 void deinitialise() override;
63 void applyToBuffer (const PluginRenderContext&) override;
64
65 //==============================================================================
66 bool takesMidiInput() override { return true; }
67 bool takesAudioInput() override { return true; }
68 bool producesAudioWhenNoAudioInput() override { return true; }
69 bool hasNameForMidiNoteNumber (int note, int midiChannel, juce::String& name) override;
70
71 juce::Array<ReferencedItem> getReferencedItems() override;
72 void reassignReferencedItem (const ReferencedItem&, ProjectItemID newID, double newStartTime) override;
73 void sourceMediaChanged() override;
74
75 void restorePluginStateFromValueTree (const juce::ValueTree&) override;
76
77 //==============================================================================
79 {
80 SamplerSound (SamplerPlugin&, const juce::String& sourcePathOrProjectID, const juce::String& name,
81 double startTime, double length, float gainDb);
82
83 void setExcerpt (double startTime, double length);
84 void refreshFile();
85
86 SamplerPlugin& owner;
87 juce::String source;
88 juce::String name;
89 int keyNote = -1, minNote = 0, maxNote = 0;
90 int fileStartSample = 0, fileLengthSamples = 0;
91 bool openEnded = false;
92 float gainDb = 0, pan = 0;
93 double startTime = 0, length = 0;
94 AudioFile audioFile;
95 juce::AudioBuffer<float> audioData { 2, 64 };
96
97 private:
99 };
100
101private:
102 //==============================================================================
103 struct SampledNote;
104
105 juce::Colour colour;
109 juce::BigInteger highlightedNotes;
110
111 juce::ValueTree getSound (int index) const;
112
113 void valueTreeChanged() override;
114 void handleAsyncUpdate() override;
115
117};
118
119}} // namespace tracktion { inline namespace engine
void applyToBuffer(const PluginRenderContext &) override
Process the next block of data.
bool hasNameForMidiNoteNumber(int note, int midiChannel, juce::String &name) override
If it's a synth that names its notes, this can return the name it uses for this note 0-127.
void sourceMediaChanged() override
Called when ProjectItem sources are re-assigned so you can reload from the new source.
void deinitialise() override
Called after play stops to release resources.
juce::String getSelectableDescription() override
Subclasses must return a description of what they are.
int getNumOutputChannelsGivenInputs(int numInputChannels) override
This must return the number of output channels that the plugin will produce, given a number of input ...
juce::String getName() const override
The name of the type, e.g.
#define TRANS(stringLiteral)
#define NEEDS_TRANS(stringLiteral)
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
constexpr Type jmin(Type a, Type b)
Passed into Plugins when they are being initialised, to give them useful contextual information that ...
The context passed to plugin render methods to provide it with buffers to fill.