Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
qishipai authored Nov 29, 2021
1 parent 90df9f0 commit d8f3ecf
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 51 deletions.
90 changes: 49 additions & 41 deletions Nlist.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
#include "MIDI.hxx"
#include "Sequ.hxx"
#include "Nlist.hxx"
using namespace NVi;
using namespace std;

template<typename T> struct rP { using t = T; };

template<typename T> struct rP<T*>{ using t = T; };
using namespace NVi;

NVnote::NVnote(double T, const NVseq_event &E):
track(E.track), Tstart(T), Tend(114514191981.0),
Tstart(T), Tend(1e20), track(E.track),
chn(E.chan), key(E.num), vel(E.value){ }

bool NVnoteList::start_parse(const char *name)
Expand All @@ -23,14 +19,14 @@ bool NVnoteList::start_parse(const char *name)

if (M.type == 2)
{
error("Nlist", "%s: 类型不支持!(format2)\n");
info ("Nlist", "支持类型: format0 format1\n");
error("Nlist", "%s: 类型不支持(fmt2)\n");
info ("Nlist", "支持类型: fmt0 fmt1\n");
return (M.mid_close(), false);
}

S.seq_start(M);
abstick = 0; Tread = 0.0; dT = 0.5 / M.ppnq;
keys = new rP<decltype(keys)>::t [M.tracks];
abstick = 0; Tread = 0; dT = .5 / M.ppnq;
keys = new stack<List_ptr> [M.tracks][128];
return true;
}

Expand All @@ -44,19 +40,17 @@ void NVnoteList::list_seek(double T)
{
if (T < Tread)
{
abstick = 0; Tread = 0.0; dT = 0.5 / M.ppnq;
abstick = 0; Tread = 0; dT = .5 / M.ppnq;
M.rewind_all(); S.seq_reset(M);
}

for (int i = 0; i < 128; ++i)
for (int k = 0; k < 128; L[k++].clear())
{
L[i].clear();

for (u16_t t = 0; t < M.tracks; ++t)
{
while (!keys[t][i].empty())
while (!keys[t][k].empty())
{
keys[t][i].pop();
keys[t][k].pop();
}
}
}
Expand All @@ -74,7 +68,7 @@ void NVnoteList::list_seek(double T)
u32_t speed = E.data[0];
speed = speed << 8 | E.data[1];
speed = speed << 8 | E.data[2];
dT = 0.000001 * speed / M.ppnq;
dT = .000001 * speed / M.ppnq;
}

S.seq_next(M);
Expand All @@ -93,29 +87,31 @@ void NVnoteList::update_to(double T)

switch (E.type)
{
case (NV_METYPE::NOON):

if (E.value > 0)
{
L[E.num].emplace_back(Tread, E);
List_ptr nt = L[E.num].end();
keys[E.track][E.num].push(--nt);
break;
}

goto _NOFF;

case (NV_METYPE::META):

if (E.num == 0x51u)
{
u32_t speed = E.data[0];
speed = speed << 8 | E.data[1];
speed = speed << 8 | E.data[2];
dT = 0.000001 * speed / M.ppnq;
dT = .000001 * speed / M.ppnq;
}

break;

case (NV_METYPE::NOON):

if (E.value > 0)
{
L[E.num].emplace_back(Tread, E);
auto nt = L[E.num].end();
keys[E.track][E.num].push(--nt);
break;
}

case (NV_METYPE::NOFF):
case (NV_METYPE::NOFF): _NOFF:

if (!keys[E.track][E.num].empty())
{
Expand All @@ -130,23 +126,35 @@ void NVnoteList::update_to(double T)
}
}

void NVnoteList::OR() // 大概有用的重叠移除器
void NVnoteList::VisualFit(double T)
{
for (int i = 0; i < 128; ++i)
for (u16_t k = 0; k < 128; ++k)
{
list<NVnote>::iterator p = L[i].end();
double T0 = 114514191981.0;
double T1 = 114514191981.0;
double T0 = 1e20, T1 = 1e20;
List_ptr p = L[k].end();

while (p-- != L[i].begin())
while (p-- != L[k].begin())
{
if (T0 < p->Tend && p->Tend < T1)
{
p->Tend = T0, T0 = p->Tstart;

if (p->Tend - p->Tstart < 1e-7)
if (p->Tend - p->Tstart < T)
{
double t = (p++)->Tstart;
(p--)->Tstart = t;
p = L[k].erase(p);
}
}
else if (T0 - p->Tstart < T * 2)
{
u16_t tr = (++p)->track;

if (tr == (--p)->track)
{
p = L[i].erase(p);
double t = (p++)->Tstart;
(p--)->Tstart = t;
p = L[k].erase(p);
}
}
else
Expand All @@ -159,13 +167,13 @@ void NVnoteList::OR() // 大概有用的重叠移除器

void NVnoteList::remove_to(double T)
{
for (int i = 0; i < 128; ++i)
for (u16_t k = 0; k < 128; ++k)
{
list<NVnote>::iterator p = L[i].begin();
List_ptr p = L[k].begin();

while (p != L[i].end() && p->Tstart < T)
while (p != L[k].end() && p->Tstart < T)
{
p->Tend < T? (p = L[i].erase(p)) : ++p;
p->Tend < T? (p = L[k].erase(p)) : ++p;
}
}
}
20 changes: 12 additions & 8 deletions Nlist.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

struct NVnote /* ===== 绘制用音符类 ===== */
{
NVi::u16_t track; // 所属轨道
double Tstart, Tend; // 首尾时间
NVi::u16_t track; // 所属轨道
NVi::nv_byte chn, key, vel; // 音符属性

NVnote(double T, const NVseq_event &E);
Expand All @@ -18,23 +18,27 @@ class NVnoteList /* ===== 音符队列类 ===== */
{
public:

NVmidiFile M; // MIDI文件
double Tread; // 当前读取位置(秒)
std::list<NVnote> L[128]; // 音符列表
using List_t = std::list<NVnote>;
using List_ptr = List_t::iterator;

NVmidiFile M; // MIDI文件
double Tread; // 当前读取位置(秒)
List_t L[128]; // 音符列表


/* 打开一个MIDI文件 */
bool start_parse(const char *name);

/* 关闭组件 */
void destroy_all();
void destroy_all(); // 关闭组件

/* 定位至T秒,并清空列表 */
void list_seek(double T);

/* 将第T秒前的音符放入列表 */
void update_to(double T);

void OR(); // 懂BM的都懂,不懂的用不到
/* 懂BM的都懂,不懂用不到 */
void VisualFit(double T);

/* 移除列表中第T秒前的音符 */
void remove_to(double T);
Expand All @@ -44,5 +48,5 @@ private:
NVsequencer S; // 事件序列器
double dT; // 速率
NVi::u32_t abstick; // 当前读取位置(tick)
std::stack<std::list<NVnote>::iterator> (*keys)[128];
std::stack<List_ptr> (*keys)[128];
};
4 changes: 2 additions & 2 deletions Player.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ int NVmain(int ac, char **av)
while (BASS_ChannelIsActive(Stm) != BASS_ACTIVE_STOPPED)
{
MIDI.update_to(Tplay + Tscr);
MIDI.remove_to(Tplay);
MIDI.OR(); Win->canvas_clear();
MIDI.remove_to(Tplay); MIDI.VisualFit(Tscr * .005);
Win->canvas_clear();

for (int k = 0; k < 128; ++k)
{
Expand Down

0 comments on commit d8f3ecf

Please sign in to comment.