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 12, 2021
1 parent 80cdb61 commit 1a88401
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 39 deletions.
39 changes: 26 additions & 13 deletions Nlist.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,42 @@ NVnote::NVnote(double T, const NVseq_event &E):
Tstart(T), Tend(114514191981.0), track(E.track),
channel(E.chan), key(E.num), vel(E.value) { }

NVnoteList::NVnoteList(const char *name):
Tread(0.0), abstick(0), keys(nullptr)
bool NVnoteList::start_parse(const char *name)
{
if ((err = !M.mid_open(name)))
if (!M.mid_open(name))
{
return;
return false;
}

print(name, "类型码: %4hu\n", M.type);
print(name, "轨道数: %4hu\n", M.tracks);
print(name, "分辨率: %4hu\n", M.ppnq);
#if defined(_WIN32) || defined(_WIN64)

if ((err = M.type == 2))
print("INFO", "类型码: %4hu\n", M.type );
print("INFO", "轨道数: %4hu\n", M.tracks);
print("INFO", "分辨率: %4hu\n", M.ppnq );

#else

print("INFO", "类型码: \e[35m%4hu\e[m\n", M.type );
print("INFO", "轨道数: \e[33m%4hu\e[m\n", M.tracks);
print("INFO", "分辨率: \e[36m%4hu\e[m\n", M.ppnq );

#endif

Tread = 0.0; abstick = 0;

if (M.type == 2)
{
error("Nlist", "%s: MIDI格式不支持!(type2)\n");
return;
M.mid_close();
error("Nlist", "%s: 类型不支持!(type=2)\n");
return false;
}

S.seq_init(M); dT = 0.5 / M.ppnq;
keys = new rmPR<decltype(keys)>::t [M.tracks];
return true;
}

NVnoteList::~NVnoteList()
void NVnoteList::destroy_all()
{
delete[] keys; keys = nullptr;
M.mid_close(); S.seq_destroy();
Expand All @@ -59,7 +72,7 @@ void NVnoteList::update_to(double T)
u32_t speed = *E.data;
(speed <<= 8) |= *(E.data + 1);
(speed <<= 8) |= *(E.data + 2);
dT = 1e-6 * speed / M.ppnq;
dT = 0.000001 * speed / M.ppnq;
}

break;
Expand Down Expand Up @@ -89,7 +102,7 @@ void NVnoteList::update_to(double T)
}
}

void NVnoteList::OR()
void NVnoteList::OR() // 大概有用吧
{
for (int i = 0; i < 128; ++i)
{
Expand Down
14 changes: 7 additions & 7 deletions Nlist.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ class NVnoteList // 音符队列
{
public:

NVmidiFile M; // MIDI文件
bool err; // 错误标志
double Tread; // 当前读取位置(秒)
std::list<NVnote> L[128]; // 音符列表
NVmidiFile M; // MIDI文件
double Tread; // 当前读取位置(秒)
std::list<NVnote> L[128]; // 音符列表

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

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

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

void OR(); // 懂BM的都懂,不懂的用不到
void OR(); // 懂BM的都懂,不懂的用不到

/* 移除列表中第T秒前的音符 */
void remove_to(double T);
Expand Down
48 changes: 29 additions & 19 deletions player.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using namespace NV;
using namespace std;

NVnoteList *MIDI;
NVnoteList MIDI;
Canvas *Win;
Canvas::color *Col;

Expand All @@ -19,7 +19,7 @@ HSTREAM Stm;

SDL_Surface *Scr;

int _WinH, pps = 4000;
int _WinH, pps = 1000;
double Tplay = 0.0, Tscr;

static void DrawNote(u16_t k, const NVnote &n)
Expand Down Expand Up @@ -81,6 +81,16 @@ BOOL CALLBACK filter(HSTREAM S, DWORD trk, BASS_MIDI_EVENT *E, BOOL sk, void *u)
return TRUE;
}

#ifndef __ANDROID__
#define NVmain main
#endif

#if defined(_WIN32) || defined(_WIN64)
#define BASSMIDI_LIB "bassmidi.dll"
#else
#define BASSMIDI_LIB "libbassmidi.so"
#endif

int NVmain(int ac, char **av)
{
if (ac != 3)
Expand All @@ -89,27 +99,24 @@ int NVmain(int ac, char **av)
return 1;
}

Win = new Canvas; MIDI = new NVnoteList(av[1]);

if (MIDI->err)
if (!MIDI.start_parse(av[1]))
{
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
Canvas C; SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Error!!!!!", "MIDI File Load Failed", nullptr);
delete MIDI; delete Win;
return 1;
}

Col = new Canvas::color [MIDI->M.tracks];
Win = new Canvas; Col = new Canvas::color [MIDI.M.tracks];

for (int i = 0; i < MIDI->M.tracks; ++i)
for (int i = 0; i < MIDI.M.tracks; ++i)
{
float ang = 6.283185307 * i / (MIDI->M.tracks + 1) * 4;
float ang = 6.283185307 * i / (MIDI.M.tracks + 1) * 4;
Col[i] = complex<float>(cosf(ang), sinf(ang)) * 512.0f;
}

_WinH = Win->WinH - Win->TH; Tscr = (double)_WinH / pps;

BASS_PluginLoad("libbassmidi.so", 0);
BASS_PluginLoad(BASSMIDI_LIB, 0);
BASS_SetConfig(BASS_CONFIG_MIDI_AUTOFONT, 0);
BASS_Init(-1, 44100, 0, 0, nullptr);

Expand All @@ -131,13 +138,13 @@ 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.update_to(Tplay + Tscr);
MIDI.remove_to(Tplay);
MIDI.OR(); Win->canvas_clear();

for (int k = 0; k < 128; ++k)
{
for (const NVnote &n : MIDI->L[KeyMap[k]])
for (const NVnote &n : MIDI.L[KeyMap[k]])
{
DrawNote(k, n);
}
Expand All @@ -150,15 +157,18 @@ int NVmain(int ac, char **av)
Tplay = BASS_ChannelBytes2Seconds(Stm, BASS_ChannelGetPosition(Stm, BASS_POS_BYTE));
}

BASS_Free(); BASS_PluginFree(0);
delete MIDI; delete Win; delete[] Col;
delete Win; delete[] Col;
BASS_Free(); BASS_PluginFree(0); MIDI.destroy_all();
return 0;
}

#ifdef __ANDROID__

int main(int ac, char **av)
{
char midi[] = "/sdcard/default.mid";
char sf [] = "/sdcard/default.sf2";
char midi[] = "/sdcard/default.mid", sf[] = "/sdcard/default.sf2";
char *arg[4]{nullptr, midi, sf, nullptr};
return NVmain(3, arg);
}

#endif

0 comments on commit 1a88401

Please sign in to comment.