private IEnumerable <KeyboardTile> ParseToKeyboardTilesInternal(Video video, NoteInstance firstNote) { var bitmaps = GetFirst500Bitmaps(video.FilePath); var startingFrame = GetStartBitmap(bitmaps); var keyboardYCoordinate = GetYCoordinateFromKeyboard(bitmaps[startingFrame]); List <KeyboardTile> keyboardTiles = GetKeyboardTilesFromKeyboard(bitmaps[startingFrame], keyboardYCoordinate, firstNote); foreach (var bitmap in bitmaps) { bitmap.Dispose(); } List <Color> AllColors = GetAllColors(); var currentFrame = startingFrame; foreach (var bitmap in GetBitmapsFrom(video.FilePath, startingFrame)) { PopulateKeyboardTiles(keyboardTiles, bitmap, keyboardYCoordinate, AllColors, currentFrame); currentFrame++; bitmap.Dispose(); } video.Framecount = currentFrame; return(keyboardTiles); }
public void UpdateObjects(double smoothTick, NoteRenderer noteRenderer, int frameIndex) { Vector3 boardPosition = board.localPosition; boardPosition.z = (float)((TickDistanceToMeters(smoothTick) % 2) * -1f + 4); if (!float.IsNaN(boardPosition.z)) { board.localPosition = boardPosition; } for (int i = 0; i < activeNotes.Count; ++i) { NoteInstance noteInstance = activeNotes[i]; Transform noteTransform = noteInstance.noteModel.transform; Vector3 pos = noteTransform.localPosition; double tickDistance = noteInstance.timestamp - smoothTick; double distanceInMeters = TickDistanceToMeters(tickDistance); pos.z = (float)distanceInMeters; noteTransform.localPosition = pos; double noteDistance = tickDistance; double noteDistanceInMeters = TickDistanceToMeters(noteDistance); double endOfNoteDistance = tickDistance + noteInstance.duration; double endOfNoteInMeters = TickDistanceToMeters(endOfNoteDistance); if (noteInstance.duration > 0) { //update long note length float length = (float)(endOfNoteInMeters - distanceInMeters); noteInstance.noteModel.SetLengt(length); } //show correct sprite SpriteRenderer spriteRenderer = noteInstance.noteModel.spriteRenderer; NoteRenderer.FredSpriteData fredSpriteData = noteRenderer.spriteData.fred[noteInstance.fred]; if (noteInstance.star) { spriteRenderer.sprite = (noteInstance.hammeron) ? fredSpriteData.starHammerOn[frameIndex % 16] : fredSpriteData.star[frameIndex % 16]; } else { spriteRenderer.sprite = (noteInstance.hammeron) ? fredSpriteData.hammerOn : fredSpriteData.normal; } if (endOfNoteInMeters < -1) //out of view { willRemove.Add(noteInstance); } } }
public void PresentationFunctionCauseWebWontWork() { if (!Directory.Exists("output")) { Directory.CreateDirectory("output"); } var videoURL = "https://www.youtube.com/watch?v=pN_gruOjM9I"; var firstNote = new NoteInstance() { Note = Notes.D, Octave = 3 }; //------------------------------------------------------------------------// //var videoURL = "https://www.youtube.com/watch?v=aCJxjDzyAT8"; // //var firstNote = new NoteInstance() { Note = Notes.F, Octave = 3 }; // // // //var videoURL = "https://www.youtube.com/watch?v=M4hAK4bTdl4"; // //var firstNote = new NoteInstance() { Note = Notes.A, Octave = 3 }; // // // //var videoURL = "https://www.youtube.com/watch?v=p1WCR7vNcIw"; // //var firstNote = new NoteInstance() { Note = Notes.E, Octave = 3 }; // //------------------------------------------------------------------------// var videoDownloader = new VideoDownloader(); var video = videoDownloader.GetVideoByUrl(new Uri(videoURL)); var keyboardTiles = new NoteParser().ParseToKeyboardTiles(video, firstNote); var musicXmlParser = new MusicXMLParser(); var musicXML = musicXmlParser.KeyboardTilesToMusicXML(keyboardTiles.ToList(), video.Framecount); File.WriteAllText(@"output\musicxml.xml", musicXML); // The output file will be inside the /bin/output folder of the NotesheetR.AppTests project // Webiste to view the musicxml.xml => https://www.soundslice.com/musicxml-viewer/ }
public void SpawnObjects(double tick, double beatsPerSecond) { if (index.note >= notes.Count) { return; //end of song } Song.Note nextNote = notes[index.note]; double tenSecondsInTicks = beatsPerSecond * 3 * resolution; if (nextNote.timestamp < tick + MetersToTickDistance(4f)) //spawn tick + 10 seconds? { //Debug.Log("New Note"); try { bool longNote = (nextNote.duration > 0); int poolNumber = (int)nextNote.fred + (longNote ? 5 : 0); NoteModel noteModel = pool.note[poolNumber][index.noteModel[poolNumber] % pool.noteSize]; GameObject newNote = noteModel.gameObject; noteModel.myTransform.rotation = cam.rotation; newNote.SetActive(true); NoteInstance noteInstance = pool.noteInstance[index.noteInstance % pool.noteInstanceSize]; index.noteInstance++; noteInstance.Update(noteModel, nextNote.timestamp, nextNote.fred, nextNote.duration, nextNote.star, nextNote.hammerOn); noteInstance.seen = false; activeNotes.Add(noteInstance); index.note++; index.noteModel[poolNumber]++; SpawnObjects(tick, beatsPerSecond); } catch (System.Exception e) { Debug.LogError(e.Message + " - " + e.StackTrace); } } }
private List <KeyboardTile> GetKeyboardTilesFromKeyboard(Bitmap bitmap, int keyboardYCoordinate, NoteInstance firstNote) { List <Color> AllColors = GetAllColors(); var AllTiles = new List <KeyboardTile>(); List <Color> KnownColors = new List <Color>() { Color.White, Color.Black, Color.Gray }; KeyboardTile currTile = GetFirstTile(bitmap, keyboardYCoordinate, firstNote); for (int x = currTile.XStart; x < bitmap.Width; x++) { var pixel = bitmap.GetPixel(x, keyboardYCoordinate); var closestColor = KnownColors[ClosestColor(KnownColors, pixel)]; var currTileColor = KnownColors[ClosestColor(KnownColors, currTile.RestingColor)]; if (currTileColor != closestColor) { if (currTile.Note == Notes.B || currTile.Note == Notes.E) { if (closestColor == Color.Black) { closestColor = Color.Gray; } } if (closestColor == Color.Gray) { switch (currTile.Note) { case Notes.B: case Notes.E: closestColor = Color.Black; pixel = Color.White; break; default: continue; } } currTile.XEnd = x - 1; currTile.XMiddle = (currTile.XEnd + currTile.XStart) / 2; var rawColor = bitmap.GetPixel(currTile.XMiddle, keyboardYCoordinate); currTile.RestingColor = AllColors[ClosestColor(AllColors, rawColor)]; AllTiles.Add(currTile); currTile = new KeyboardTile() { XStart = x, RestingColor = pixel, Note = NextNoteDict[currTile.Note], Octave = currTile.Octave }; if (currTile.Note == Notes.A) { currTile.Octave = currTile.Octave + 1; } } } var wrongTiles = AllTiles.Where(x => x.XStart + 2 > x.XEnd).ToList(); if (wrongTiles.Count != 0) { throw new Exception("Could not read the Keyboard tiles from video"); } return(AllTiles); }
private static KeyboardTile GetFirstTile(Bitmap bitmap, int keyboardYCoordinate, NoteInstance firstNote) { List <Color> KnownColors = new List <Color>() { Color.White, Color.Black }; for (int x = 2; x < bitmap.Width; x++) { var pixel = bitmap.GetPixel(x, keyboardYCoordinate); var closestColor = KnownColors[ClosestColor(KnownColors, pixel)]; if (closestColor.Name.Contains("White") || closestColor.Name == "Transparent") { return(new KeyboardTile() { XStart = x, RestingColor = Color.White, Note = firstNote.Note, Octave = firstNote.Octave }); } } throw new Exception("First tile could not be found."); }
public IEnumerable <KeyboardTile> ParseToKeyboardTiles(Video video, NoteInstance firstNote) { return(ParseToKeyboardTilesInternal(video, firstNote)); }