/// <summary> /// PartからGameNotesを作成します。 /// </summary> /// <param name="scorePart"></param> /// <returns></returns> private IEnumerable <GameNote> CreateGameNotes(ScorePart scorePart) { long currentTick = 0; var gamePart = new GamePart(); var gameNoteList = new List <GameNote>(); foreach (var measure in scorePart.MeasureList) { foreach (var note in measure.Notes) { GameNote?gameNote = null; if (note.IsRest) { //フェルマータがついている休符のみ休符として追加する if (note.HasFermata) { gameNote = new GameNote(x: GetX(currentTick), tick: currentTick, type: note.Type, isRest: note.IsRest, hasDot: note.HasDot); } } else { gameNote = new GameNote(x: GetX(currentTick), tick: currentTick, type: note.Type, isRest: note.IsRest, hasDot: note.HasDot); } //消費分すすめる currentTick += GetTicks(note); if (gameNote != null) { yield return(gameNote.Value); } } } }
//Reads the top level score static public ScoreProperties ReadScore(ScorePartwise scorePartwise) { //get the top level properties of the score ScoreProperties i = new ScoreProperties(); if (scorePartwise.getWork() != null) { i.WorkTitle = scorePartwise.getWork().getWorkTitle(); } if (scorePartwise.getMovementTitle() != null) { i.MovementTitle = scorePartwise.getMovementTitle(); } if (scorePartwise.getIdentification().getEncoding().getEncodingDateOrEncoderOrSoftware().get(0) != null) { javax.xml.bind.JAXBElement x = (javax.xml.bind.JAXBElement)scorePartwise.getIdentification().getEncoding().getEncodingDateOrEncoderOrSoftware().get(0); i.EncodingSoftware = x.getValue().ToString(); } if (scorePartwise.getCredit().size() > 0) { Credit credit = (Credit)scorePartwise.getCredit().get(0); if (credit.getCreditTypeOrLinkOrBookmark().get(0) is FormattedText) { FormattedText ft = (FormattedText)credit.getCreditTypeOrLinkOrBookmark().get(0); i.CreditWords = ft.getValue(); } } PartList partlist = scorePartwise.getPartList(); if (partlist.getPartGroupOrScorePart().get(0) is ScorePart) { ScorePart scorepart = (ScorePart)partlist.getPartGroupOrScorePart().get(0); i.ScorePartID = scorepart.getId(); i.PartDisplayName = scorepart.getPartName().getValue(); i.PartAbbreviation = scorepart.getPartAbbreviation() is PartName?scorepart.getPartAbbreviation().getValue() : ""; ScoreInstrument scoreinstrument = (ScoreInstrument)scorepart.getScoreInstrument().get(0); i.InstrumentID = scoreinstrument.getId(); i.InstrumentName = scoreinstrument.getInstrumentName(); if (scorepart.getMidiDeviceAndMidiInstrument().get(0) is MidiInstrument) { MidiInstrument midiinstrument = (MidiInstrument)scorepart.getMidiDeviceAndMidiInstrument().get(0); i.MidiChannel = midiinstrument.getMidiChannel(); i.MidiProgram = midiinstrument.getMidiProgram(); } } if (scorePartwise.getPart().size() > 0) { i.Part = (ScorePartwise.Part)scorePartwise.getPart().get(0); } return(i); }
public string KeyboardTilesToMusicXML(List <KeyboardTile> keyboardTiles, int frameCount) { // Downloaded youtube videos always have a fps of 23.98 int videoLength = frameCount / 24; int measureCount = videoLength / 2; ScorePartwisePartMeasure[] measures = new ScorePartwisePartMeasure[measureCount]; for (int i = 0; i < measureCount; i++) { measures[i] = new ScorePartwisePartMeasure(); measures[i].Number = i.ToString(); } Dictionary <Note, int> NoteFrameDict = new Dictionary <Note, int>(); foreach (var keyboardTile in keyboardTiles) { foreach (var press in keyboardTile.TilePresses) { var startFrame = press.Item1; var endFrame = press.Item2; Pitch keyboardPitch = new Pitch(); keyboardPitch.Octave = keyboardTile.Octave.ToString(); keyboardPitch.Step = NotesToMusicXMLStep[keyboardTile.Note]; keyboardPitch.Alter = NoteToAlter(keyboardTile.Note); double startSec = startFrame / 24; int measureIndex = (int)(startSec / 2); var measure = measures[measureIndex]; Note pressNote = new Note(); pressNote.Pitch = keyboardPitch; pressNote.Type = DurationToNodeType(press); measure.Note.Add(pressNote); NoteFrameDict.Add(pressNote, startFrame); } } for (int i = 0; i < measures.Length; i++) { var measure = measures[i]; Note[] notes = new Note[measure.Note.Count]; var notesOrdered = notes.OrderBy(x => NoteFrameDict[x]).Select(x => x); measure.Note.CopyTo(notes, 0); while (measure.Note.Count > 0) { measure.Note.RemoveAt(0); } foreach (var note in notesOrdered) { measure.Note.Add(note); } var lastFrame = 0; foreach (var note in measure.Note) { var startFrame = NoteFrameDict[note]; if (lastFrame == startFrame) { note.Chord = new Empty(); } lastFrame = startFrame; } } ScorePartwise spw = new ScorePartwise(); PartList partList = new PartList(); ScorePart scorePart = new ScorePart(); PartName partName = new PartName(); partName.Value = "NotesheetR"; scorePart.PartName = partName; scorePart.Id = "1"; partList.ScorePart = scorePart; ScorePartwisePart part = new ScorePartwisePart(); part.Id = "1"; foreach (var measure in measures) { part.Measure.Add(measure); } spw.Part.Add(part); spw.PartList = partList; return(ParseToXml(spw)); }
//***************************************** Create Object Factory *******************************************// //The Object Factory, Used to create the elements of the score as required //***************************************** ScorePartwise *******************************************// // Create the top level Partwise Score Element public static ScorePartwise CreateScorePartwise(ScoreProperties i) { ObjectFactory factory = new ObjectFactory(); //Create a scorepart ScorePartwise.Part part; Marshalling.getContext(); ///////////////////// Following are the main components required for the Score in Phase 1 //***************************************** ScorePartwise *******************************************// ScorePartwise scorePartwise = factory.createScorePartwise(); // Set the version of MusicXML scorePartwise.setVersion("3.0"); //***************************************** Set Work and Movement Titles *******************************************// // Create the work element and set its title Work work = factory.createWork(); work.setWorkTitle(i.WorkTitle); //Setting some properties of the root element. scorePartwise.setMovementTitle(i.MovementTitle); //Set the work title of the scorepartwise scorePartwise.setWork(work); //***************************************** Create and set Identification Element *******************************************// //Create identification and set its properties Identification identification = factory.createIdentification(); com.audiveris.proxymusic.Encoding encoding = factory.createEncoding(); //set the software used for encoding encoding.getEncodingDateOrEncoderOrSoftware().add(factory.createEncodingSoftware(i.EncodingSoftware)); // set the encoding identification.setEncoding(encoding); scorePartwise.setIdentification(identification); //***************************************** Set the Credit words *******************************************// Credit credit = factory.createCredit(); FormattedText creditwordtext = new FormattedText(); creditwordtext.setValue(i.CreditWords); credit.getCreditTypeOrLinkOrBookmark().add(creditwordtext); scorePartwise.getCredit().add(credit); //***************************************** Create a PartList *******************************************// PartList partlist = factory.createPartList(); // create a scorepart ScorePart scorepart = factory.createScorePart(); ////////////////////////Some Properties of the scorepart PartName partname = factory.createPartName(); partname.setValue(i.PartDisplayName); scorepart.setPartName(partname); //set part abbreviation partname.setValue(i.PartAbbreviation); scorepart.setPartAbbreviation(partname); //set the scorepart id scorepart.setId(i.ScorePartID); // set the scorepart instrument ScoreInstrument scoreinstrument = factory.createScoreInstrument(); scoreinstrument.setId(i.InstrumentID); scoreinstrument.setInstrumentName(i.InstrumentName); scorepart.getScoreInstrument().add(scoreinstrument); //set the midi device parameters MidiInstrument midiinstrument = factory.createMidiInstrument(); //set midi instrument Id midiinstrument.setId(scoreinstrument); //set midi channel java.lang.Integer midichannel = i.MidiChannel; //channel number midiinstrument.setMidiChannel(midichannel); //set midi program java.lang.Integer midiprogram = i.MidiProgram; //program number midiinstrument.setMidiProgram(midiprogram); scorepart.getMidiDeviceAndMidiInstrument().add(midiinstrument); // add the scorepart to the partlist partlist.getPartGroupOrScorePart().add(scorepart); //Ambiguity scorePartwise.setPartList(partlist); //***************************************** Create a Part *******************************************// if (i.Part == null) { part = factory.createScorePartwisePart(); } else { part = i.Part; } //set part id part.setId(scorepart); // Add the part to the score scorePartwise.getPart().add(part); return(scorePartwise); }