using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MODTest.Modplayer { public class MODTools { // effect decoder public uint effect(uint cmd) { return cmd >> 8; } public uint effect_ext(uint cmd) { return effect_x(cmd); } public uint effect_x(uint cmd) { return (cmd & 0xf0) >> 4; } public uint effect_y(uint cmd) { return cmd & 0xf; } public uint effect_xy(uint cmd) { return cmd & 0xff; } // SortedDictionary sNoteTable = new SortedDictionary(); public enum e_CellStyle { DOT_STYLE, PT_STYLE }; public string rawChannelToNote(UInt32 din, e_CellStyle style = e_CellStyle.DOT_STYLE) { if (sNoteTable.Count == 0) { /* | | C | | D | | | F | | G | | A | | | | # | | # | | | # | | # | | # | | | | | | | | | | | | | | | | | D | | E | | | G | | A | | B | | | | b | | b | | | b | | b | | b | | | |___| |___| | |___| |___| |___| | | | | | | | | | | C | D | E | F | G | A | B | |_____|_____|_____|_____|_____|_____|_____| */ sNoteTable[856] = "C-1"; sNoteTable[808] = "C#1"; sNoteTable[762] = "D-1"; sNoteTable[720] = "D#1"; sNoteTable[678] = "E-1"; sNoteTable[640] = "F-1"; sNoteTable[604] = "F#1"; sNoteTable[570] = "G-1"; sNoteTable[538] = "G#1"; sNoteTable[508] = "A-1"; sNoteTable[480] = "A#1"; sNoteTable[453] = "B-1"; sNoteTable[428] = "C-2"; sNoteTable[404] = "C#2"; sNoteTable[381] = "D-2"; sNoteTable[360] = "D#2"; sNoteTable[339] = "E-2"; sNoteTable[320] = "F-2"; sNoteTable[302] = "F#2"; sNoteTable[285] = "G-2"; sNoteTable[269] = "G#2"; sNoteTable[254] = "A-2"; sNoteTable[240] = "A#2"; sNoteTable[226] = "B-2"; sNoteTable[214] = "C-3"; sNoteTable[202] = "C#3"; sNoteTable[190] = "D-3"; sNoteTable[180] = "D#3"; sNoteTable[170] = "E-3"; sNoteTable[160] = "F-3"; sNoteTable[151] = "F#3"; sNoteTable[143] = "G-3"; sNoteTable[135] = "G#3"; sNoteTable[127] = "A-3"; sNoteTable[120] = "A#3"; sNoteTable[113] = "B-3"; } UInt32 sampleNumber = ((din >> 28) << 4) | ((din >> 12) & 0xf); UInt32 periode = (din >> 16) & 0xfff; UInt32 effect = din & 0xfff; string sout = ""; switch (style) { case e_CellStyle.PT_STYLE: sout = sNoteTable.ContainsKey(periode) ? sNoteTable[periode] : " - "; sout += sampleNumber > 0 ? string.Format(" {0:X2}", sampleNumber) : " 00"; sout += string.Format(" {0:X3}", effect); break; default: case e_CellStyle.DOT_STYLE: sout = sNoteTable.ContainsKey(periode) ? sNoteTable[periode] : "..."; sout += sampleNumber > 0 ? string.Format(" {0:X2}", sampleNumber) : " .."; sout += effect > 0 ? string.Format(" {0:X3}", effect) : " ..."; break; } return sout; } protected UInt16 endian(UInt16 din) { return (UInt16)((din >> 8) | (din << 8)); } protected UInt32 endian(UInt32 din) { return (din >> 24) | ((din >> 8) & 0x0000ff00) | ((din << 8) & 0x00ff0000) | (din << 24); } protected string bytesToString(byte[] rawSongName) { string rString = ""; foreach (byte b in rawSongName) { if (b != 0) { rString += (char)b; } } return rString; } protected string longToString(UInt32 din) { string rString = ""; rString += (char)(din & 0xff); rString += (char)((din >> 8) & 0xff); rString += (char)((din >> 16) & 0xff); rString += (char)(din >> 24); return rString; } protected float clamp(float v, float min, float max) { v = v > max ? max : v; v = v < min ? min : v; return v; } protected int clamp(int v, int min, int max) { v = v > max ? max : v; v = v < min ? min : v; return v; } protected uint clamp(uint v, uint min, uint max) { v = v > max ? max : v; v = v < min ? min : v; return v; } } }