public MIDISong ToMidi(Dictionary<string, int> instrumentMap, int songId = 0) { var inst = Instruments; var ovtb = Voices; var stbl = Songs[songId]; var notb = Notes; var song = new MIDISong(); for(int i = 0; i < 4; i++) { var track = song.AddTrack(null); song.SetTempo(track, 3000/stbl.SongSpeed); song.SetTimeSignature(track, 4, 4); } for(int i = 0; i < inst.Length; i++) { var instr = inst[i]; int minst; if(!instrumentMap.TryGetValue(instr.Name, out minst)) { Console.WriteLine("Unknown instrument "+instr.Name); }else{ Console.WriteLine(minst+" set for "+instr.Name); } if(i < 15 && i != 9) { for(int j = 0; j < 4; j++) { if(minst != -1) { song.SetChannelInstrument(j, i, minst); } } } } int lastinstr = Int32.MinValue; for(int i = stbl.StartPos; i <= stbl.StopPos; i++) { for(int j = 0; j < 4; j++) { var voice = ovtb[i*4+j]; for(int k = 0; k < stbl.PatternLength; k++) { var note = notb[voice.NoteAddress+k]; if(note.Command == 15) { for(int l = 0; l < 4; l++) { song.SetTempo(l, 3000/note.CommandInfo); } } int instr = note.Instrument-1; if(instr >= 0) { if(instr == 9 || instr >= 15) { if(lastinstr != instr) { int minst; instrumentMap.TryGetValue(inst[instr].Name, out minst); song.SetChannelInstrument(j, 15, minst); lastinstr = instr; } song.AddNote(j, 15, note.Value-1, 12); }else{ song.AddNote(j, instr, note.Value-1, 12); } }else{ song.AddNote(j, 0, -1, 12); } } } } return song; }
public static void Main(string[] args) { /*var hip = new JHPlayer(); using(var stream = new FileStream("hipc.Title", FileMode.Open)) { hip.loader(stream); var mid = new MIDISong(); for(int i = 0; i < 4; i++) mid.AddTrack(); }*/ var hip = HippelCosoFile.Open("hipc.City_Walk", null); var song = new MIDISong(); for(int i = 0; i < 4; i++) { var track = song.AddTrack(null); song.SetTempo(track, 3000/hip.Songs[0].Speed); song.SetTimeSignature(track, 4, 4); } /*for(int i = 0; i < hip.Voices.Length/4; i++) { for(int j = 0; j < 4; j++) { var voice = hip.Voices[i*4+j]; int vsize = 12; for(int k = 0; k < vsize; k++) { int note = hip.Patterns[voice.PatternAddress*vsize+k].Note*2; //if(note <= 5) note = 0; song.AddNote(j, 0, note-1, 12); } } }*/ for(int i = 0; i < hip.Patterns.Length; i++) { int note = hip.Patterns[i].Note; song.AddNote(0, 0, note*2-1, 12); } using(var stream = new FileStream("hip.mid", FileMode.Create)) { song.Save(stream); } return; var cfg = ReadConfig(); Console.WriteLine("AmiMus v"+Assembly.GetExecutingAssembly().GetName().Version.ToString(2)); Console.WriteLine("Created by [email protected]"); if(args.Length != 2) { Console.WriteLine("Usage:"); Console.WriteLine(" amimus [input] [output]"); Console.WriteLine("Example:"); Console.WriteLine(" amimus [sa.Song1] [Song1.mid]"); Console.WriteLine("Currently supported formats:"); Console.WriteLine("Input - Sonic Arranger (classic or with replayer)"); Console.WriteLine("Output - MIDI"); }else{ SA2MIDI(args[0], args[1]); Console.WriteLine("Song converted."); } }