Skip to content

Commit

Permalink
"Regenerate Division" tool
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoru committed Nov 28, 2020
1 parent 4504162 commit 68afa1b
Show file tree
Hide file tree
Showing 12 changed files with 382 additions and 291 deletions.
1 change: 1 addition & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ add_executable(bmhelper WIN32
src/smf_event.cpp
src/smf_io.h
src/srcview.cpp
src/srcview.h src/AudioSplitter.cpp src/AudioSplitter.h src/wavsplit.cpp src/wavsplit.h)
src/srcview.h src/AudioSplitter.cpp src/AudioSplitter.h src/wavsplit.cpp src/wavsplit.h src/divsettingdialog.h)

include(${wxWidgets_USE_FILE})
target_link_libraries(bmhelper ${wxWidgets_LIBRARIES} ${LIBSNDFILE_LIBRARIES})
Expand Down
14 changes: 14 additions & 0 deletions src/divedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "AudioSplitter.h"
#include <wx/clipbrd.h>
#include <wx/dialog.h>
#include "divsettingdialog.h"

enum {
ID_SmfOutput,
Expand Down Expand Up @@ -387,4 +388,17 @@ void DivisionEditor::OnOpenAudioSplitter(wxCommandEvent &event) {
splitter->Show();
}

bool DivisionEditor::OnDivRegenerate(wxMenuEvent &event) {
if (!division) return false;
DivisionSetting setting(division->get_name(), division->get_quantize());

DivisionSettingDialog dialog(frame, setting, division->get_quantize());
if (dialog.ShowModal() != wxID_OK)
return false;

dialog.GetSetting(setting);
division->change_division_settings(setting);
return true;
}


52 changes: 47 additions & 5 deletions src/division.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@ static void sort_notes(

Division::Division(Project *_project, MidiData &src, const DivisionSetting &setting)
: MidiData(src.get_quantize()), project(_project), name(setting.name), zz_enabled(setting.zz_definition) {
divide_from_data(src, setting);
}

void Division::divide_from_data(MidiData &src, const DivisionSetting &setting, bool copy) {
if (copy)
src_data = src; // store a copy of the src data...

init(); /* clean ourselves up */

name = setting.name;

std::vector<ReferredNote> temp_divs;
std::vector<int> src2div(src.notes_count());
src2def.resize(src.notes_count());
Expand All @@ -205,21 +216,27 @@ Division::Division(Project *_project, MidiData &src, const DivisionSetting &sett
note.referrers.push_back(i);
src2div[i] = i;
}

// Midiデータにそのまま配置
for (size_t i = 0; i < temp_divs.size(); i++) {
note_push_back(
MidiNoteEvent(src.notes(i).position + setting.head_margin, temp_divs[i].gate, temp_divs[i].nn,
temp_divs[i].vel));
}
if (src.notes_count() > 0) head_margin = src.notes(0).position+setting.head_margin;

if (src.notes_count() > 0) head_margin = src.notes(0).position + setting.head_margin;
} else {
// 分割
ThresholdSetting thresholds{};
thresholds.gate = setting.gate_threshold;
thresholds.vel = setting.velocity_threshold;
ThresholdSetting thresholds {
static_cast<int>(setting.gate_threshold),
static_cast<int>(setting.velocity_threshold)
};

divide_notes(src, src2div, temp_divs, thresholds);

// ソート
sort_notes(temp_divs, src2div, setting.sort_type);

// Midiデータに流し込み
int position = setting.head_margin;
for (auto & temp_div : temp_divs) {
Expand All @@ -228,6 +245,7 @@ Division::Division(Project *_project, MidiData &src, const DivisionSetting &sett
int b = position % get_quantize();
if (b) position += get_quantize() - b;
}

head_margin = setting.head_margin;
}

Expand Down Expand Up @@ -258,18 +276,19 @@ Division::Division(Project *_project, MidiData &src, const DivisionSetting &sett
} else {
mln = 1; // 多重定義しない
}

size_t id_i = definitions.size();
for (size_t b = 0; b < mln; b++) {
definitions.push_back(Definition(zz, i));
if (setting.zz_definition) zz++; else zz.increment_in_ff();
}

size_t b = 0;
for (int referrer : temp_divs[i].referrers) {
src2def[referrer] = id_i + b;
if (++b == mln) b = 0;
}
}

}


Expand Down Expand Up @@ -366,6 +385,7 @@ static const NodeName _name_ = StringToNodeName("name");
static const NodeName _s2df_ = StringToNodeName("s2df");
static const NodeName _dfnt_ = StringToNodeName("dfnt");
static const NodeName _zzen_ = StringToNodeName("zzen");
static const NodeName _srcd_ = StringToNodeName("Srcd"); /* source data (first letter caps = list) */

struct BmsOffsetData {
bool zz_enabled;
Expand Down Expand Up @@ -400,6 +420,8 @@ bool Division::read_tree(TreeNode &node) {
sub.get_data(&data, sizeof(BmsOffsetData));
zz_enabled = data.zz_enabled;
}
} else if (sub.get_name() == _srcd_) {
src_data.read_tree(sub);
}
}
return true;
Expand Down Expand Up @@ -430,8 +452,28 @@ bool Division::write_tree(TreeNode &node) {

node.push_back(_zzen_);
node.back().set_data(&offset_data, sizeof(BmsOffsetData));

node.push_back(_srcd_);
src_data.write_tree(node.back());

return true;
}

void Division::change_division_settings(const DivisionSetting &setting) {
divide_from_data(src_data, setting, false);
}


DivisionSetting::DivisionSetting(const wxString &name, size_t quantize) {
this->name = name;
src_copy = false;
head_margin = 0;
min_interval = quantize*1;
sort_type = DivisionSetting::SORT_NN_GATE_V;
gate_threshold = quantize/8;
velocity_threshold = 5;
zz_definition = true;
ml_definition = true;
start_definition = 1;
ml_threshold = quantize/2;
}
8 changes: 7 additions & 1 deletion src/division.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct DivisionSetting{
ZZNumber start_definition; // �J�n��`�ԍ�
int ml_threshold; // ���d��`���邩�ǂ����̃m�[�g�Ԋu��臒l(���l���ݒ�B���x�̏ꍇ�͑��d��`���Ȃ�)

DivisionSetting(const wxString &name, size_t quantize);
};


Expand Down Expand Up @@ -60,14 +61,16 @@ class Division : public MidiData{
int head_margin;
bool zz_enabled;

MidiData src_data;

//void _divide_notes(std::vector<int> &src2div, std::vector<ReferredNote> &temp_divs, ThresholdSetting &thresholds);
//void _sort_notes(std::vector<ReferredNote> &temp_divs, DivisionSetting::SortType sort_type);

public:
Division(Project *_project);
Division(Project *_project, MidiData &src, const DivisionSetting &setting);
void init() override {
//MidiData::init();
MidiData::init();
name.clear();
src2def.clear();
definitions.clear();
Expand All @@ -94,6 +97,9 @@ class Division : public MidiData{
void def_transpose_up();
void def_transpose_down();
void def_transpose_to(ZZNumber nbegin);

void divide_from_data(MidiData &src, const DivisionSetting &setting, bool copy = true);
void change_division_settings(const DivisionSetting &setting);
};


Expand Down
64 changes: 64 additions & 0 deletions src/divsettingdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef BMHELPER_DIVSETTINGDIALOG_H
#define BMHELPER_DIVSETTINGDIALOG_H

class DivisionSettingDialog : public wxDialog{
enum{
ID_NameLabel = 1,
ID_NameInput = 2,
ID_MidiBox = 30,
ID_ScpyCheck = 29,
ID_MhmgLabel = 32,
ID_MhmgInput = 33,
ID_MintLabel = 3,
ID_MintInput = 4,
ID_SortLabel = 5,
ID_SortCombo = 6,
ID_ThrsLabel = 20,
ID_TgatLabel = 7,
ID_TgatInput = 8,
ID_TvelLabel = 9,
ID_TvelInput = 10,
ID_DefnBox = 31,
// ID_DfzzLabel = 11,
ID_DfzzCheck = 12,
ID_DfmlCheck = 21,
ID_DfstLabel = 13,
ID_DfstInput = 14,
ID_DfmtLabel = 22,
ID_DfmtInput = 23
};
wxStaticText *name_label;
wxTextCtrl *name_input;
wxStaticBox *midi_box;
wxCheckBox *scpy_check;
wxStaticText *mhmg_label;
wxTextCtrl *mhmg_input;
wxStaticText *mint_label;
wxTextCtrl *mint_input;
wxStaticText *sort_label;
wxComboBox *sort_combo;
wxStaticText *thrs_label;
wxStaticText *tgat_label;
wxTextCtrl *tgat_input;
wxStaticText *tvel_label;
wxTextCtrl *tvel_input;
wxStaticBox *defn_box;
// wxStaticText *dfzz_label;
wxCheckBox *dfzz_check;
wxCheckBox *dfml_check;
wxStaticText *dfst_label;
wxTextCtrl *dfst_input;
wxStaticText *dfmt_label;
wxTextCtrl *dfmt_input;
wxButton *button_ok, *button_cancel;
int quantize;
static const int _lm=15, _tm=5, _lw=25, _lb=30, _fc=150, _sc=130, _bw=5, _cw=25;
public:
DivisionSettingDialog(wxWindow *owner, DivisionSetting setting, int _quantize);
void GetSetting(DivisionSetting &setting);
void OnScpyCheck(wxCommandEvent &WXUNUSED(ev));
void OnOK(wxCommandEvent &WXUNUSED(ev));
wxDECLARE_EVENT_TABLE();
};

#endif //BMHELPER_DIVSETTINGDIALOG_H
Loading

0 comments on commit 68afa1b

Please sign in to comment.