public string UpdateBarlinesFromLilypond() //Channelcommand to update the barlines from the text in the editor (see class LilyADPConverter { return(this.lilypondText.Dispatcher.Invoke( () => { ADPSheet sheet = lilyADPConverter.ConvertText(lilypondText.Text); if (sheet != null) { showSheetVisualisation(sheet.getTrack()); } return this.lilypondText.Text; } )); }
private void btn_ShowContent_Click(object sender, RoutedEventArgs e) //Shows the content of a midi file in the tracks section of the MainWindow, also shows the sheetvisualisation { string extension = txt_MidiFilePath.Text.Split('.').Last(); if (extension == "mid") { showMidiTracks(MidiReader.ReadMidi(txt_MidiFilePath.Text)); //MidiConverter midiConverter = new MidiConverter(); //MyMusicSheet mss = midiConverter.convertMidi(txt_MidiFilePath.Text); //ShowTrack(mss.Tracks[1], mss.TimeSignature[0], mss.TimeSignature[1]); MidiADPConverter midiConverter = new MidiADPConverter(); ADPSheet sheet = midiConverter.ReadFile(txt_MidiFilePath.Text); showSheetVisualisation(sheet.Tracks[1]); } }
public void OpenFile() //Opens a filedialog where you can select a file to open, accepts: midi and lilypond files { OpenFileDialog openFileDialog = new OpenFileDialog() { Filter = "Midi Files(.mid)|*.mid|Lily files (*.ly*)|*.ly*" }; if (openFileDialog.ShowDialog() == true) { txt_MidiFilePath.Text = openFileDialog.FileName; ADPSheet sheet = firstFileConverter.Handle(openFileDialog.FileName); if (sheet != null) { showSheetVisualisation(sheet.getTrack()); NoteToLilypondConverter ntlc = new NoteToLilypondConverter(); lilypondText.Text = ntlc.GetLilypond(sheet); SetNewState(); } } }
public string GetLilypond(ADPSheet _musicSheet) //Converts the ADPSheet to a string so it can be put as lilypond text in the editor (See function: convertMusicalSymbols) { string result = ""; result += "\\relative c' { \n"; result += "\\clef treble \n"; result += "\\time "; result += _musicSheet.getTrack().Bars[1].TimeSignature[0]; result += "/"; result += _musicSheet.getTrack().Bars[1].TimeSignature[1]; result += " \n"; result += "\\tempo 4=120 \n"; // add notes result += convertMusicalSymbols(_musicSheet.getTrack().Bars); result += "}"; return(result); }
public override ADPSheet ReadFile(String _path) //Reads the path name and converts it to an ADPSheet and returns it as such. { var sequence = new Sequence(); sequence.Load(_path); ADPSheet returnSheet = new ADPSheet(); ADPTrack tempADPTrack; ADPMusicalSymbol tempADPMusicalSymbol; int[] timeSignature = new int[2]; bool timeSignatureIsSet = false; double wholeNoteLength = sequence.Division * 4; int barAbsoluteTime = (int)wholeNoteLength; List <Track> tracks = new List <Track>(); for (int i = 0; i < sequence.Count; i++) { tracks.Add(sequence[i]); } foreach (Track t in tracks) { tempADPTrack = new ADPTrack(); ADPBar tempADPBar = new ADPBar(); tempADPBar.TimeSignature = timeSignature; foreach (MidiEvent midiEvent in t.Iterator()) { // musical symbol if (midiEvent.MidiMessage.MessageType == MessageType.Channel) { var channelMessage = midiEvent.MidiMessage as ChannelMessage; if (channelMessage.Command == ChannelCommand.NoteOn || channelMessage.Command == ChannelCommand.NoteOff) { string[] inputStrings = convertToInputStrings(channelMessage, midiEvent, wholeNoteLength); if (inputStrings != null) { tempADPMusicalSymbol = musicalSymbolFactory.GetMusicalSymbol(inputStrings); if (tempADPMusicalSymbol != null) { tempADPBar.MusicalSymbols.Add(tempADPMusicalSymbol); if (midiEvent.AbsoluteTicks % (barAbsoluteTime) == 0) { //last musical symbol in bar tempADPTrack.Bars.Add(tempADPBar); tempADPBar = new ADPBar(); tempADPBar.TimeSignature = timeSignature; } } } } } // info over track if (midiEvent.MidiMessage.MessageType == MessageType.Meta) { var metaMessage = midiEvent.MidiMessage as MetaMessage; if (metaMessage.MetaType == MetaType.TrackName) { tempADPTrack.Name = MidiReader.GetMetaString(metaMessage); } if (metaMessage.MetaType == MetaType.TimeSignature) { if (!timeSignatureIsSet) { byte[] bytes = metaMessage.GetBytes(); timeSignature[0] = bytes[0]; timeSignature[1] = (int)Math.Pow(2, bytes[1]); barAbsoluteTime = calculateBarLength(timeSignature, wholeNoteLength); timeSignatureIsSet = true; } } } } returnSheet.Tracks.Add(tempADPTrack); } return(returnSheet); }
public ADPSheet ConvertContent(string[] _content) //Takes a string array and converts it to an ADPSheet, then returns it { int[] timeSignature = new int[2]; ADPNote latestNote = new ADPNote(); latestNote.Key = "C"; latestNote.Octave = 4; ADPMusicalSymbol tempMusicalSymbol; ADPBar tempBar; int alternativeNr = 0; string tempo = "error"; string key = "error"; contentType type = contentType.none; ADPSheet adps = new ADPSheet(); ADPTrack adpt = new ADPTrack(); adpt.Name = "LilypondTrack"; List <ADPMusicalSymbol> notes = new List <ADPMusicalSymbol>(); List <List <ADPMusicalSymbol> > alternatives = new List <List <ADPMusicalSymbol> >(); for (int i = 2; i < _content.Length; i++) { string temp = _content[i]; switch (_content[i]) { case "": break; case "\\tempo": tempo = _content[i + 1]; i++; break; case "\\time": string str = _content[i + 1]; timeSignature[0] = (int)Char.GetNumericValue(str[0]); timeSignature[1] = (int)Char.GetNumericValue(str[2]); i++; break; case "\\repeat": tempBar = new ADPBar(); tempBar.MusicalSymbols = notes; int[] tempTimeSignature = new int[2]; tempTimeSignature[0] = timeSignature[0]; tempTimeSignature[1] = timeSignature[1]; tempBar.TimeSignature = tempTimeSignature; //adpt.Bars.Add(tempBar); notes = new List <ADPMusicalSymbol>(); i++; i++; break; case "\\alternative": //type = contentType.alternativeBlok; break; case "\\clef": key = _content[i + 1]; i++; break; case "|": //add maatstreep / new bar? if (type == contentType.alternative) { //Had een Alternative maatstreep gemaakt } else { tempBar = new ADPBar(); tempBar.MusicalSymbols = notes; tempTimeSignature = new int[2]; tempTimeSignature[0] = timeSignature[0]; tempTimeSignature[1] = timeSignature[1]; tempBar.TimeSignature = tempTimeSignature; adpt.Bars.Add(tempBar); notes = new List <ADPMusicalSymbol>(); } break; case "{": //add alternative if alternativeblock if (type == contentType.alternativeBlok) { type = contentType.alternative; alternatives.Add(new List <ADPMusicalSymbol>()); } break; case "}": //close alternative if alternativeblock //if (type == contentType.alternative) //{ // type = contentType.alternativeBlok; // alternativeNr++; //} //else //{ // type = contentType.none; //} if (notes.Count > 0) { ADPBar tempBar2 = new ADPBar(); tempBar2.MusicalSymbols = notes; tempBar2.TimeSignature = timeSignature; adpt.Bars.Add(tempBar2); notes = new List <ADPMusicalSymbol>(); } break; case "}}": //End of File break; case "~": break; default: if (type == contentType.alternative) { //add alternative note string[] inputStrings = convertToInputStrings(_content[i], latestNote); if (inputStrings != null) { tempMusicalSymbol = musicalSymbolFactory.GetMusicalSymbol(inputStrings); if (tempMusicalSymbol is ADPNote) { latestNote = (ADPNote)tempMusicalSymbol; } alternatives[alternativeNr].Add(tempMusicalSymbol); } } else { //add normal note string[] inputStrings = convertToInputStrings(_content[i], latestNote); if (inputStrings != null) { tempMusicalSymbol = musicalSymbolFactory.GetMusicalSymbol(inputStrings); if (tempMusicalSymbol is ADPNote) { latestNote = (ADPNote)tempMusicalSymbol; } notes.Add(tempMusicalSymbol); } } break; } } adps.Tracks.Add(adpt); //Only need to add one track return(adps); }