public void IntensityChange(StreamWriter sw, MIDINote PrintingNote, ref int intIntensity, bool changedNotetypeFlag) { string hexIntensity; intIntensity = PrintingNote.intensity; if (intIntensity == 0) //failsafe to prevent intensity 0 and repeated intensities { intIntensity = 10; } if (TrackNumber == 2) { if (intIntensity < 4) { intIntensity = 3; } else if (intIntensity < 11) { intIntensity = 2; } else { intIntensity = 1; } } if (CapitalHex) { hexIntensity = intIntensity.ToString("X"); //converts intensity value into hexadecimal } else { hexIntensity = intIntensity.ToString("x"); //converts intensity value into hexadecimal } if (TrackNumber < 3 & hexIntensity != StringIntensity) //doesn't calculate the intensity for TrackNumber 4 and if it doesn't need to be changed { StringIntensity = hexIntensity; if (StringIntensity == "0") { StringIntensity = "a"; } if (!changedNotetypeFlag) { sw.Write("\tintensity $"); sw.Write(StringIntensity); if (TrackNumber == 0) { sw.WriteLine(Envelopes[0]); } else if (TrackNumber == 1) { sw.WriteLine(Envelopes[1]); } else if (TrackNumber == 2) { sw.WriteLine(Envelopes[2]); // defaults to Wave 0 in the wave channel } } } }
public void NotesAndNoiseArray(StreamWriter sw, MIDINote PrintingNote) { string NoiseTemplateString; if (TrackNumber == 3 & NoiseTemplate) //checks if the noise replace mode is true and if we're in Track 3 (noise) { if (PrintingNote.RawNote == 0) { NoiseTemplateString = "__"; } else { NoiseTemplateString = "N" + PrintingNote.octave + PrintingNote.RawNote.ToString("X"); } sw.Write(NoiseTemplateString); if (!NoiseReplaceList.Contains(NoiseTemplateString) & NoiseTemplateString != "__") { NoiseReplaceList.Add(NoiseTemplateString); } } else { sw.Write(notesArray[PrintingNote.RawNote]); } }
public MIDINote(MIDINote Copy) { NoteDuration = Copy.NoteDuration; NoteLocation = Copy.NoteLocation; RawNote = Copy.RawNote; octave = Copy.octave; intensity = Copy.intensity; pan = Copy.pan; warnings = Copy.warnings; }
public void NotePrinter(StreamWriter sw, MIDINote PrintingNote, int noteLengthFinal) { if (noteLengthFinal == 0) //makes sure actual zeros are zeros { sw.Write("\t;note "); NotesAndNoiseArray(sw, PrintingNote); sw.Write(", "); sw.Write(0); if (PrintWarnings) { sw.Write(" | "); sw.Write("WARNING: Rounded down to 0"); } sw.WriteLine(""); goto End; } while (noteLengthFinal >= 16) { sw.Write("\tnote "); NotesAndNoiseArray(sw, PrintingNote); sw.Write(", "); sw.WriteLine(16); noteLengthFinal -= 16; } if (noteLengthFinal > 0) { sw.Write("\tnote "); NotesAndNoiseArray(sw, PrintingNote); sw.Write(", "); sw.Write(noteLengthFinal); if (notetypeCheck != 0 & PrintWarnings == true) { sw.Write(" ; "); sw.Write("WARNING: Rounded."); } if (PrintWarnings & AutoSync) { sw.Write(PrintingNote.warnings); } sw.WriteLine(""); } End :; }
public void NotetypeChange(StreamWriter sw, MIDINote PrintingNote, ref bool changedNotetypeFlag) { int newNotetype = allowedNotetypes[BaseNotetypeLocation]; unitaryLength = Convert.ToInt32((double)TimeDivision * newNotetype / 48); //checks if there's need to change the notetype i.e. if remainder of the division by the unitary length is not 0 notetypeCheck = Convert.ToInt32((double)(PrintingNote.NoteDuration % unitaryLength)); for (int pos = 0; pos < allowedNotetypes.Length & notetypeCheck != 0; pos++) { newNotetype = allowedNotetypes[pos]; unitaryLength = Convert.ToInt32((double)TimeDivision * newNotetype / 48); notetypeCheck = PrintingNote.NoteDuration % unitaryLength; } if (newNotetype != notetype) { changedNotetypeFlag = true; notetype = newNotetype; sw.Write("\tnotetype {0}", notetype); if (TrackNumber < 2) { sw.WriteLine(", ${0}7", StringIntensity); } else if (TrackNumber == 2) //wave channel { sw.WriteLine(", ${0}0", StringIntensity); } else { sw.WriteLine(); } } notetypeCheck = Convert.ToInt32((double)(PrintingNote.NoteDuration % unitaryLength)); }
public void GBPrinter(List <MIDINote>[] TrackList) { int bar = 0; int intIntensity = 10; StringIntensity = "a"; notetype = allowedNotetypes[BaseNotetypeLocation]; int noteLengthFinal; TrackNumber = 0; //tracknumber starts at 0 here because of indexes StreamWriter sw = new StreamWriter(string.Concat(directoryPath, ASMFileName, ".asm"), true, Encoding.ASCII); //Header sw.WriteLine(";Coverted using MIDI2ASM"); sw.WriteLine(";Code by TriteHexagon"); sw.WriteLine(";Version 5.0.1 (7-Feb-2021)"); sw.WriteLine(";Visit github.com/TriteHexagon/Midi2ASM-Converter for up-to-date versions."); sw.WriteLine(""); sw.WriteLine("; ============================================================================================================"); sw.WriteLine(""); sw.WriteLine("Music_Placeholder:"); sw.WriteLine("\tmusicheader 4, 1, Music_Placeholder_Ch1"); sw.WriteLine("\tmusicheader 1, 2, Music_Placeholder_Ch2"); sw.WriteLine("\tmusicheader 1, 3, Music_Placeholder_Ch3"); sw.WriteLine("\tmusicheader 1, 4, Music_Placeholder_Ch4"); sw.WriteLine(""); while (TrackNumber < TrackList.Length)//reuse the same variable { sw.WriteLine("Music_Placeholder_Ch{0}:", TrackNumber + 1); //writes the rest of the header switch (TrackNumber) { case 0: sw.WriteLine("\tvolume $77"); sw.WriteLine("\tdutycycle ${0}", Dutycycles[0]); sw.Write("\tnotetype {0}", notetype); sw.WriteLine(", ${0}{1}", StringIntensity, Envelopes[0]); if (Tempo != 0) { sw.WriteLine("\ttempo {0}", Tempo); } break; case 1: sw.WriteLine("\tdutycycle ${0}", Dutycycles[1]); sw.Write("\tnotetype {0}", notetype); sw.WriteLine(", ${0}{1}", StringIntensity, Envelopes[1]); break; case 2: sw.Write("\tnotetype {0}", notetype); sw.WriteLine(", $1{0}", Envelopes[2]); break; case 3: sw.WriteLine("\ttogglenoise {0} ; WARNING: this might sound bad.", Togglenoise); sw.Write("\tnotetype {0}", notetype); sw.WriteLine(); break; default: MessageBox.Show("Number of tracks exceeded the max. Reduce the number of tracks and try again."); break; } //removes the beginning rests for (int i = 0; i < TrackList.Length; i++) { if (TrackList[i].Count() > 0) { if (TrackList[i].ElementAt(0).NoteDuration == 0 & TrackList[i].ElementAt(0).RawNote == 0) { TrackList[i].RemoveAt(0); } } } for (int NoteIndex = 0; NoteIndex < TrackList[TrackNumber].Count; NoteIndex++) { bool changedNotetypeFlag = false; //copies the current note to the temporary PrintingNote MIDINote PrintingNote = new MIDINote(TrackList[TrackNumber][NoteIndex]); BarWriter(sw, ref bar); NotetypeChange(sw, PrintingNote, ref changedNotetypeFlag); noteLengthFinal = Convert.ToInt32(Math.Round((double)PrintingNote.NoteDuration / unitaryLength)); //changes Octave if (PrintingNote.octave != octave & PrintingNote.RawNote != 0 & TrackNumber != 3) //doesn't change the octave for TrackNumber 3 (Noise), for rests and if the previous octave is the same { if (TrackNumber == 2) { sw.Write("\toctave {0}", PrintingNote.octave); //... except in the Wave channel if (PrintWarnings & PrintingNote.octave == 0) { sw.WriteLine(" ;WARNING: Octave 0 isn't supported, won't work correctly"); } else { sw.WriteLine(); } } else { sw.Write("\toctave {0}", PrintingNote.octave - 1); //the octave appears to be always 1 lower in the ASM... if (PrintWarnings & PrintingNote.octave - 1 == 0) { sw.WriteLine(" ;WARNING: Octave 0 isn't supported, won't work correctly"); } else { sw.WriteLine(); } } octave = PrintingNote.octave; } //calculates the intensity of the note and checks if it needs to be changed if (!IgnoreIntensity) { IntensityChange(sw, PrintingNote, ref intIntensity, changedNotetypeFlag); } LengthSum[TrackNumber] += noteLengthFinal * notetype; //prints note NotePrinter(sw, PrintingNote, noteLengthFinal); } sw.WriteLine("\tendchannel"); sw.WriteLine(""); sw.WriteLine("; ============================================================================================================"); sw.WriteLine(""); TrackNumber++; octave = -1; StringIntensity = "a"; bar = 0; } sw.Close(); if (NoiseTemplate) { NoiseReplaceList.Sort(); if (File.Exists(string.Concat(directoryPath, ASMFileName, "-nt.txt"))) { FileStream fileStream = File.Open(string.Concat(directoryPath, ASMFileName, "-nt.txt"), FileMode.Open); fileStream.SetLength(0); fileStream.Close(); } StreamWriter nt = new StreamWriter(string.Concat(directoryPath, ASMFileName, "-nt.txt"), true, Encoding.ASCII); foreach (string i in NoiseReplaceList) { nt.WriteLine(i); } nt.Close(); } }