xtc/src/gui/JUCE/sample_editor.hpp

44 lines
2 KiB
C++

#ifndef XTC_SAMPLE_EDITOR_HPP
#define XTC_SAMPLE_EDITOR_HPP
#include "xtc/xtc_sample.h"
#include "ui.hpp"
#include <functional>
#include <memory>
#include <vector>
class UiValue_Input;
class UiBox;
class SampleCanvas;
class SampleEditor : public UiDouble_Window {
public:
/* Takes ownership of loaded snapshot. Modal edits never touch audio callbacks. */
using Data=std::unique_ptr<xtc_sample,decltype(&xtc_sample_destroy)>;
explicit SampleEditor(Data sample);
std::function<xtc_result(unsigned int,size_t,size_t)> trim;
xtc_result trim_clip();
std::function<xtc_result(const xtc_sample *,const char *)> adopt;
xtc_result save_copy(const char *path,bool use_in_project);
xtc_result export_selection(const char *path);
xtc_result process(xtc_sample_operation operation,double amount=0);
xtc_result undo_sample();
xtc_result select_audible(double threshold,size_t padding);
xtc_result snap_zero_crossings(size_t radius);
std::function<xtc_result(unsigned int,const std::vector<size_t> &)> slice;
xtc_result detect_attacks(double threshold,size_t gap);
xtc_result slice_clip();
const std::vector<size_t> &attacks() const {return attacks_;}
void run();
xtc_result select(size_t begin,size_t end);
xtc_result view(size_t begin,unsigned int zoom);
const xtc_sample *sample() const {return sample_.get();}
size_t begin() const {return begin_;} size_t end() const {return end_;}
size_t frames() const {return frames_;} size_t origin() const {return origin_;}
unsigned int zoom() const {return zoom_;}
void refresh();
private:
std::unique_ptr<xtc_sample,decltype(&xtc_sample_destroy)> sample_{nullptr,xtc_sample_destroy};
std::unique_ptr<xtc_sample,decltype(&xtc_sample_destroy)> previous_{nullptr,xtc_sample_destroy};
std::vector<size_t> attacks_;
size_t frames_=0,begin_=0,end_=0,origin_=0;unsigned int rate_=0,zoom_=1;
UiValue_Input *begin_input_,*end_input_,*origin_input_;UiBox *stats_;SampleCanvas *canvas_;
};
#endif