diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Plugins/Input/in_midi/cmf.cpp | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/Plugins/Input/in_midi/cmf.cpp')
-rw-r--r-- | Src/Plugins/Input/in_midi/cmf.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Src/Plugins/Input/in_midi/cmf.cpp b/Src/Plugins/Input/in_midi/cmf.cpp new file mode 100644 index 00000000..0eb4f552 --- /dev/null +++ b/Src/Plugins/Input/in_midi/cmf.cpp @@ -0,0 +1,48 @@ +#include "main.h" +#include "cvt.h" + +bool is_cmf(const BYTE* buf,size_t s) +{ + return s>0x20 && *(DWORD*)buf == _rv('CTMF'); +} + +static BYTE tempodat[7]={0,0xFF,0x51,0x03,0,0,0}; + +bool load_cmf(MIDI_file * mf,const BYTE* ptr,size_t sz) +{ + if (sz < 14) + return 0; + + WORD music_offset = *(WORD*)(ptr+8); + if ((size_t)music_offset > sz) + return 0; + const BYTE* _t=ptr+music_offset; + size_t total_size=sz - music_offset; + mf->size=14+8+7+total_size; + BYTE* _pt=(BYTE*)malloc(mf->size); + if (!_pt) return 0; + + mf->data=_pt; + *(DWORD*)_pt=_rv('MThd'); + _pt+=4; + *(DWORD*)_pt=_rv(6); + _pt+=4; + *(WORD*)_pt=0; + _pt+=2; + *(WORD*)_pt=0x0100; + _pt+=2; + *(WORD*)_pt=rev16(*(WORD*)(ptr+10)); + _pt+=2; + *(DWORD*)_pt=_rv('MTrk'); + _pt+=4; + *(DWORD*)_pt=rev32(total_size+7); + _pt+=4; + DWORD tm=(DWORD)(48000000/(*(WORD*)(ptr+12))); + tempodat[4]=(BYTE)((tm>>16)&0xFF); + tempodat[5]=(BYTE)((tm>>8)&0xFF); + tempodat[6]=(BYTE)(tm&0xFF); + memcpy(_pt,tempodat,7); + _pt+=7; + memcpy(_pt,_t,total_size); + return 1; +}
\ No newline at end of file |