Vital
Loading...
Searching...
No Matches
wavetable_creator.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4#include "wave_frame.h"
5#include "wavetable_group.h"
6#include "file_source.h"
7#include "json/json.h"
8#include "wavetable.h"
9
10using json = nlohmann::json;
11
12class LineGenerator;
13
28public:
41
50 full_normalize_(true), remove_all_dc_(true) { }
51
52 int getGroupIndex(WavetableGroup* group);
53 void addGroup(WavetableGroup* group) { groups_.push_back(std::unique_ptr<WavetableGroup>(group)); }
54 void removeGroup(int index);
55 void moveUp(int index);
56 void moveDown(int index);
57
63 int numGroups() const { return static_cast<int>(groups_.size()); }
64
71 WavetableGroup* getGroup(int index) const { return groups_[index].get(); }
72
73 float render(int position);
74 void render();
75 void postRender(float max_span);
76 void renderToBuffer(float* buffer, int num_frames, int frame_size);
77 void init();
78 void clear();
79 void loadDefaultCreator();
80
82 void initFromAudioFile(const float* audio_buffer, int num_samples, int sample_rate,
83 AudioFileLoadStyle load_style, FileSource::FadeStyle fade_style);
84
90 void setName(const std::string& name) { wavetable_->setName(name); }
91
97 void setAuthor(const std::string& author) { wavetable_->setAuthor(author); }
98
104 void setFileLoaded(const std::string& path) { last_file_loaded_ = path; }
105
111 std::string getName() const { return wavetable_->getName(); }
112
118 std::string getAuthor() const { return wavetable_->getAuthor(); }
119
125 std::string getLastFileLoaded() { return last_file_loaded_; }
126
133 static bool isValidJson(json data);
134
135 json updateJson(json data);
137 void jsonToState(json data);
138
145
146protected:
147 void initFromSplicedAudioFile(const float* audio_buffer, int num_samples, int sample_rate,
148 FileSource::FadeStyle fade_style);
149 void initFromVocodedAudioFile(const float* audio_buffer, int num_samples, int sample_rate, bool ttwt);
150 void initFromPitchedAudioFile(const float* audio_buffer, int num_samples, int sample_rate);
151 void initFromLineGenerator(LineGenerator* line_generator);
152
155 std::vector<std::unique_ptr<WavetableGroup>> groups_;
156
157 std::string last_file_loaded_;
161
162 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WavetableCreator)
163};
FadeStyle
Different methods to blend or interpolate the loaded audio window into a wavetable frame.
Definition file_source.h:38
A class for generating and storing a line shape, defined by a series of points and associated powers.
Definition line_generator.h:20
A class responsible for creating complete wavetables from groups of wavetable components.
Definition wavetable_creator.h:27
void initPredefinedWaves()
Definition wavetable_creator.cpp:171
void initFromLineGenerator(LineGenerator *line_generator)
Definition wavetable_creator.cpp:292
bool full_normalize_
Definition wavetable_creator.h:159
void removeGroup(int index)
Definition wavetable_creator.cpp:51
void setFileLoaded(const std::string &path)
Records the path of the last file loaded to create this wavetable.
Definition wavetable_creator.h:104
WavetableGroup * getGroup(int index) const
Retrieves a WavetableGroup by index.
Definition wavetable_creator.h:71
json updateJson(json data)
Definition wavetable_creator.cpp:321
static bool isValidJson(json data)
Checks if a given JSON data represents a valid wavetable creator state.
Definition wavetable_creator.cpp:309
vital::WaveFrame compute_frame_combine_
Definition wavetable_creator.h:153
void moveUp(int index)
Definition wavetable_creator.cpp:37
void setAuthor(const std::string &author)
Sets the author of the wavetable.
Definition wavetable_creator.h:97
std::string getAuthor() const
Gets the author of the wavetable.
Definition wavetable_creator.h:118
void initFromPitchedAudioFile(const float *audio_buffer, int num_samples, int sample_rate)
Definition wavetable_creator.cpp:271
void addGroup(WavetableGroup *group)
Definition wavetable_creator.h:53
void loadDefaultCreator()
Definition wavetable_creator.cpp:163
void init()
Definition wavetable_creator.cpp:151
void clear()
Definition wavetable_creator.cpp:157
AudioFileLoadStyle
Defines how audio files are interpreted when loading into a wavetable.
Definition wavetable_creator.h:33
@ kWavetableSplice
Slice the audio into segments mapping onto wavetable frames.
Definition wavetable_creator.h:35
@ kNone
Definition wavetable_creator.h:34
@ kTtwt
Similar to vocoded but optimized for TTWT (text-to-wavetable).
Definition wavetable_creator.h:37
@ kVocoded
Apply vocoder-like analysis to extract fundamental cycles.
Definition wavetable_creator.h:36
@ kPitched
Attempts to extract pitch-based cycles from the audio.
Definition wavetable_creator.h:38
@ kNumDragLoadStyles
Definition wavetable_creator.h:39
std::string last_file_loaded_
Definition wavetable_creator.h:157
json stateToJson()
Definition wavetable_creator.cpp:477
void jsonToState(json data)
Definition wavetable_creator.cpp:493
int numGroups() const
Gets the total number of WavetableGroups.
Definition wavetable_creator.h:63
int getGroupIndex(WavetableGroup *group)
Definition wavetable_creator.cpp:29
void initFromAudioFile(const float *audio_buffer, int num_samples, int sample_rate, AudioFileLoadStyle load_style, FileSource::FadeStyle fade_style)
Definition wavetable_creator.cpp:196
vital::Wavetable * getWavetable()
Gets the internal wavetable object being created.
Definition wavetable_creator.h:144
bool remove_all_dc_
Definition wavetable_creator.h:160
vital::Wavetable * wavetable_
Definition wavetable_creator.h:158
void moveDown(int index)
Definition wavetable_creator.cpp:44
void render()
Definition wavetable_creator.cpp:89
void initFromVocodedAudioFile(const float *audio_buffer, int num_samples, int sample_rate, bool ttwt)
Definition wavetable_creator.cpp:243
std::string getName() const
Gets the name of the wavetable.
Definition wavetable_creator.h:111
std::vector< std::unique_ptr< WavetableGroup > > groups_
Definition wavetable_creator.h:155
vital::WaveFrame compute_frame_
Definition wavetable_creator.h:154
void renderToBuffer(float *buffer, int num_frames, int frame_size)
Definition wavetable_creator.cpp:117
void postRender(float max_span)
Definition wavetable_creator.cpp:109
void setName(const std::string &name)
Sets the name of the wavetable.
Definition wavetable_creator.h:90
std::string getLastFileLoaded()
Gets the last loaded file path.
Definition wavetable_creator.h:125
WavetableCreator(vital::Wavetable *wavetable)
Constructs a WavetableCreator associated with a given Wavetable object.
Definition wavetable_creator.h:49
void initFromSplicedAudioFile(const float *audio_buffer, int num_samples, int sample_rate, FileSource::FadeStyle fade_style)
Definition wavetable_creator.cpp:210
A class representing a group of WavetableComponents combined to form part of a wavetable.
Definition wavetable_group.h:24
Represents a single frame of a wavetable, containing both time-domain and frequency-domain data.
Definition wave_frame.h:16
A class representing a wavetable, holding multiple frames of waveforms and their frequency-domain rep...
Definition wavetable.h:20
std::string getAuthor()
Get the author of this wavetable.
Definition wavetable.h:122
std::string getName()
Get the user-defined name of this wavetable.
Definition wavetable.h:115
void setName(const std::string &name)
Set a user-defined name for this wavetable.
Definition wavetable.h:129
void setAuthor(const std::string &author)
Set the author for this wavetable.
Definition wavetable.h:136
nlohmann::json json
Definition line_generator.h:7