private static void ScanSongFilesAsThread() { SetSongScanStatus("Initializing scan of song information files..."); FolderScanner scannerTxt = new FolderScanner("*.txt"); List <string> txtFiles = new List <string>(); SetSongScanStatus("Scanning for matching file names in songs folder..."); txtFiles = scannerTxt.GetFiles((string)SettingsManager.GetSetting(ESetting.SongDir)); SetSongScanStatus(String.Format("Discovered a total of {0} possible song data files...", txtFiles.Count)); int counter = 0; txtFiles.ForEach(delegate(string path) { counter += 1; SetSongScanStatus(String.Format("Scanning file {0} of {1} possible song data files...", counter, txtFiles.Count)); try { if (SongParser.ParseSongFile(path)) { Debug.Log("success::" + path); } else { Debug.Log("nope::" + path); } } catch (Exception ex) { Debug.LogException(ex); } SetSongScanStatus("Song files scan finished."); }); }
public void ItemMoveEnded(int fromPosition, int toPosition) { fromPosition--; toPosition--; if (MusicPlayer.CurrentID() > fromPosition && MusicPlayer.CurrentID() <= toPosition) { MusicPlayer.currentID--; } else if (MusicPlayer.CurrentID() < fromPosition && MusicPlayer.CurrentID() >= toPosition) { MusicPlayer.currentID++; } else if (MusicPlayer.CurrentID() == fromPosition) { MusicPlayer.currentID = toPosition; } SongParser.QueueSlotMoved(fromPosition, toPosition); if (MusicPlayer.UseCastPlayer) { int nextItemID = MusicPlayer.RemotePlayer.MediaQueue.ItemCount > toPosition?MusicPlayer.RemotePlayer.MediaQueue.ItemIdAtIndex(toPosition + 1) : 0; //0 = InvalidItemID = end of the queue MusicPlayer.RemotePlayer.QueueReorderItems(new int[] { MusicPlayer.RemotePlayer.MediaQueue.ItemIdAtIndex(fromPosition) }, nextItemID, null); } MusicPlayer.UpdateQueueDataBase(); }
public void Parse_Throws_WhenSchemeIsInvalid() { var sut = new SongParser(); var url = "xxx://Song Title=LastName FirstName=Style=Ab=n=T44*A{C^7 |A-7 |D-9 |G7#5 }"; Assert.Throws <Exception>(() => sut.Parse(url)); }
/// <summary> /// Displays the setting fields for the .mn file setup. /// </summary> private void DrawMNFileSettings() { EditorGUILayout.LabelField("Song Settings", EditorStyles.boldLabel); EditorGUILayout.HelpBox("All song files (music, .mn, banner, and background) must be in the same directory!", MessageType.Info); EditorGUILayout.BeginVertical(); songTitle = EditorGUILayout.TextField("Title", songTitle); if (SongParser.IsNullOrWhiteSpace(songTitle)) { EditorGUILayout.HelpBox("Song title cannot be empty or whitespace.", MessageType.Warning); } subtitle = EditorGUILayout.TextField("Subtitle", subtitle); artist = EditorGUILayout.TextField("Artist", artist); if (SongParser.IsNullOrWhiteSpace(artist)) { EditorGUILayout.HelpBox("Artist cannot be empty or whitespace.", MessageType.Warning); } EditorGUILayout.BeginHorizontal(); bannerPath = EditorGUILayout.TextField("Banner Path", bannerPath); if (GUILayout.Button("Change Banner Image")) { string _bannerPath = EditorUtility.OpenFilePanel("Change Banner Image", "", "*"); _bannerPath = Path.GetFileName(_bannerPath); bannerPath = _bannerPath; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); backgroundPath = EditorGUILayout.TextField("Backgorund Path", backgroundPath); if (GUILayout.Button("Change Background Image")) { string _backgroundPath = EditorUtility.OpenFilePanel("Change Banner Image", "", "*"); _backgroundPath = Path.GetFileName(_backgroundPath); backgroundPath = _backgroundPath; } EditorGUILayout.EndHorizontal(); offset = EditorGUILayout.FloatField("Offset", offset); EditorGUILayout.LabelField("Song Length: " + musicClip.length); sampleStart = EditorGUILayout.Slider("Sample Start Time", sampleStart, 0.0f, musicClip.length); sampleLength = EditorGUILayout.Slider("Sample Length Time", sampleLength, 0.0f, musicClip.length - sampleStart); bpm = EditorGUILayout.FloatField("BPM", bpm); if (bpm <= 0.0f) { EditorGUILayout.HelpBox("Invalid BPM.", MessageType.Error); } EditorGUILayout.EndVertical(); }
public void Parse_Returns_Style() { var sut = new SongParser(); var url = "irealbook://Song Title=LastName FirstName=Style=Ab=n=T44*A{C^7 |A-7 |D-9 |G7#5 }"; var song = sut.Parse(url); Assert.Equal("Style", song.Style); }
public void Parse_Returns_KeySignature() { var sut = new SongParser(); var url = "irealbook://Song Title=LastName FirstName=Style=Ab=n=T44*A{C^7 |A-7 |D-9 |G7#5 }"; var song = sut.Parse(url); Assert.Equal(KeySignature.AFlatMajor, song.KeySignature); }
public void CanParseExamplesSuccesfully() { var paths = Examples.GetAll(); var songParser = new SongParser(); var songs = songParser.ParseSongs(paths); var mismatchedFileNames = songs.Select(x => $"\\{x.Artist} - {x.Name}.mp3").Where(x => !paths.Any(y => y.EndsWith(x))).ToArray(); Assert.That(songs.Count, Is.EqualTo(paths.Length)); Assert.That(songs.Select(x => x.Path).All(x => paths.Contains(x)), Is.True); Assert.That(mismatchedFileNames.Length, Is.EqualTo(0)); Assert.Pass(); }
/// <summary> /// Checks the validity of the .mn setup settings. /// </summary> /// <returns>True or false.</returns> private bool IsMNDataValid() { if (SongParser.IsNullOrWhiteSpace(songTitle)) { return(false); } if (SongParser.IsNullOrWhiteSpace(artist)) { return(false); } if (bpm <= 0.0f) { return(false); } return(true); }
void Start() { Screen.SetResolution(800, 1280, false); SongParser parsetest = new SongParser(); enabled = false; currentSong = parsetest.parse("Assets/Simfiles/Kung Fu Beat.sm"); currentChart = currentSong.charts [0]; AudioSource audioSource = gameObject.GetComponent <AudioSource> (); AudioClip audioFile = Resources.Load("Kung Fu Beat") as AudioClip; while (audioFile.loadState == AudioDataLoadState.Loading) { Debug.Log("Loading"); } if (audioFile.loadState == AudioDataLoadState.Loaded) { audioSource.clip = audioFile; audioSource.Play(); } else { Debug.Log("Error Loading Song"); } //Debug.Log (currentSong.offset); enabled = true; score = 0; health = 100; combo = 0; scrollSpeed = 1f; bpm = currentSong.bpms[bpmIndex].value; currentChart = currentSong.charts [0]; artistText.text = currentSong.artist; titleText.text = currentSong.title; judge = ""; for (int i = 0; i < currentSong.bpms.Count; i++) { //Debug.Log ($"{currentSong.bpms[i].value} at {currentSong.bpms [i].time}"); } }
private void OnDoWork(object sender, DoWorkEventArgs e) { backgroundWorker.ReportProgress(0, "Initialising parser"); var songParser = new SongParser(); backgroundWorker.ReportProgress(10, "Enumerating files"); var files = Directory.EnumerateFiles(musicDirectory, "*", System.IO.SearchOption.AllDirectories) .Where(x => new[] { ".aac", ".flac", ".mp3", ".ogg", ".wav", ".wma" }.Contains(Path.GetExtension(x))) .ToImmutableList(); backgroundWorker.ReportProgress(40, "Parsing songs"); var parsedSongs = songParser.ParseSongs(files); backgroundWorker.ReportProgress(70, $"Picking songs from {parsedSongs.Count} found songs"); var songPicker = new SongPicker(playlistSize, artistAndSongSpacing); var pickedSongs = songPicker.PickSongs(parsedSongs); backgroundWorker.ReportProgress(100, "Finished picking songs"); e.Result = pickedSongs; }
public void Tests() { const int PlaylistSize = 500; const int ArtistAndSongSpacing = 100; var paths = Examples.GetAll(); var songParser = new SongParser(); var songs = songParser.ParseSongs(paths); for (var i = 0; i < 1; i++) { var songPicker = new SongPicker(PlaylistSize, ArtistAndSongSpacing); var pickedSongs = songPicker.PickSongs(songs); Assert.That(pickedSongs.Count, Is.EqualTo(PlaylistSize)); var artists = new Queue <string>(); var names = new Queue <string>(); foreach (var song in pickedSongs) { Assert.That(artists.Contains(song.Artist), Is.False); Assert.That(names.Contains(song.Name), Is.False); artists.Enqueue(song.Artist); names.Enqueue(song.Name); if (artists.Count > ArtistAndSongSpacing) { artists.Dequeue(); } if (names.Count > ArtistAndSongSpacing) { names.Dequeue(); } } } }
public void TestParseCreatesValidObjectWithMultipleWriters() { #region data = ... var data = @"- ""Hear my song, Violetta"" (uncredited) Written by Othmar Klose, Rudolph Lukesch and 'Harry S. Pepper' (qv) Performed by 'Carmen Silvera' (qv)"; #endregion IList <string> songDefinition = new List <string>(data.Split(new string[] { "\r\n" }, StringSplitOptions.None)); var expected = new Song { Title = "Hear my song, Violetta", Composer = "Othmar Klose, Rudolph Lukesch and Harry S. Pepper", Lyricist = "Othmar Klose, Rudolph Lukesch and Harry S. Pepper", Performer = "Carmen Silvera" }; var logger = new Mock <ILog>(); Song actual = new SongParser(logger.Object).Parse(songDefinition); Assert.AreEqual(expected, actual); }
public void TestParseCreatesValidObjectWithMultipleCrossReferencedWriters() { #region data = ... var data = @"- ""Boom"" Written by 'E. Ray Goetz' (qv) (uncredited) and 'Charles Trenet' (qv) (uncredited) Performed by 'Carmen Silvera' (qv) "; #endregion IList<string> songDefinition = new List<string>(data.Split(new string[] { "\r\n" }, StringSplitOptions.None)); var expected = new Song { Title = "Boom", Composer = "E. Ray Goetz (uncredited) and Charles Trenet (uncredited)", Lyricist = "E. Ray Goetz (uncredited) and Charles Trenet (uncredited)", Performer = "Carmen Silvera" }; var logger = new Mock<ILog>(); Song actual = new SongParser(logger.Object).Parse(songDefinition); Assert.AreEqual(expected, actual); }
public void TestParseCreatesValidObjectWithCorrectlyFormattedDefinition() { #region data = ... var data = @"- ""Without a Dream"" Music by 'Charles Fox (I)' (qv) Lyrics by 'Norman Gimbel' (qv) Performed by 'Ron Dante' (qv)"; #endregion IList <string> songDefinition = new List <string>(data.Split(new string[] { "\r\n" }, StringSplitOptions.None)); var expected = new Song { Title = "Without a Dream", Composer = "Charles Fox (I)", Lyricist = "Norman Gimbel", Performer = "Ron Dante" }; var logger = new Mock <ILog>(); Song actual = new SongParser(logger.Object).Parse(songDefinition); Assert.AreEqual(expected, actual); }
public void TestParseCreatesValidObjectWithCorrectlyFormattedDefinition() { #region data = ... var data = @"- ""Without a Dream"" Music by 'Charles Fox (I)' (qv) Lyrics by 'Norman Gimbel' (qv) Performed by 'Ron Dante' (qv)"; #endregion IList<string> songDefinition = new List<string>(data.Split(new string[] {"\r\n"}, StringSplitOptions.None)); var expected = new Song { Title = "Without a Dream", Composer = "Charles Fox (I)", Lyricist = "Norman Gimbel", Performer = "Ron Dante" }; var logger = new Mock<ILog>(); Song actual = new SongParser(logger.Object).Parse(songDefinition); Assert.AreEqual(expected, actual); }
public void TestParseCreatesValidObjectWithMultipleCrossReferencedWriters() { #region data = ... var data = @"- ""Boom"" Written by 'E. Ray Goetz' (qv) (uncredited) and 'Charles Trenet' (qv) (uncredited) Performed by 'Carmen Silvera' (qv) "; #endregion IList <string> songDefinition = new List <string>(data.Split(new string[] { "\r\n" }, StringSplitOptions.None)); var expected = new Song { Title = "Boom", Composer = "E. Ray Goetz (uncredited) and Charles Trenet (uncredited)", Lyricist = "E. Ray Goetz (uncredited) and Charles Trenet (uncredited)", Performer = "Carmen Silvera" }; var logger = new Mock <ILog>(); Song actual = new SongParser(logger.Object).Parse(songDefinition); Assert.AreEqual(expected, actual); }
public void Parse_Returns_SongChart() { var sut = new SongParser(); var url = "irealbook://Song Title=LastName FirstName=Style=Ab=n=T44*A{C^7 |A-7 |D-9 |G7#5 }"; var song = sut.Parse(url); Assert.Equal(new Token { Type = TokenType.TimeSignature, Symbol = "T44" }, song.SongChart.Tokens[0]); Assert.Equal(new Token { Type = TokenType.RehearsalMark, Symbol = "*A" }, song.SongChart.Tokens[1]); Assert.Equal(new Token { Type = TokenType.BarLine, Symbol = "{" }, song.SongChart.Tokens[2]); Assert.Equal(new Token { Type = TokenType.Chord, Symbol = "C" }, song.SongChart.Tokens[3]); Assert.Equal(new Token { Type = TokenType.ChordQuality, Symbol = "^7" }, song.SongChart.Tokens[4]); Assert.Equal(new Token { Type = TokenType.EmptyCell, Symbol = " " }, song.SongChart.Tokens[5]); Assert.Equal(new Token { Type = TokenType.BarLine, Symbol = "|" }, song.SongChart.Tokens[6]); Assert.Equal(new Token { Type = TokenType.Chord, Symbol = "A" }, song.SongChart.Tokens[7]); Assert.Equal(new Token { Type = TokenType.ChordQuality, Symbol = "-7" }, song.SongChart.Tokens[8]); Assert.Equal(new Token { Type = TokenType.EmptyCell, Symbol = " " }, song.SongChart.Tokens[9]); Assert.Equal(new Token { Type = TokenType.BarLine, Symbol = "|" }, song.SongChart.Tokens[10]); Assert.Equal(new Token { Type = TokenType.Chord, Symbol = "D" }, song.SongChart.Tokens[11]); Assert.Equal(new Token { Type = TokenType.ChordQuality, Symbol = "-9" }, song.SongChart.Tokens[12]); Assert.Equal(new Token { Type = TokenType.EmptyCell, Symbol = " " }, song.SongChart.Tokens[13]); Assert.Equal(new Token { Type = TokenType.BarLine, Symbol = "|" }, song.SongChart.Tokens[14]); Assert.Equal(new Token { Type = TokenType.Chord, Symbol = "G" }, song.SongChart.Tokens[15]); Assert.Equal(new Token { Type = TokenType.ChordQuality, Symbol = "7#5" }, song.SongChart.Tokens[16]); Assert.Equal(new Token { Type = TokenType.EmptyCell, Symbol = " " }, song.SongChart.Tokens[17]); Assert.Equal(new Token { Type = TokenType.BarLine, Symbol = "}" }, song.SongChart.Tokens[18]); Assert.Equal(19, song.SongChart.Tokens.Length); }
public SongParserTests() { _songParser = new SongParser(); }
static void Main(string[] args) { // documentation https://github.com/anthonyreilly/ConsoleArgs/ var app = new CommandLineApplication(); // This should be the name of the executable itself. // the help text line "Usage: ConsoleArgs" uses this app.Name = "Playlist generator for DirEttore (.dpl files)"; app.Description = $"Program to generate long playlists for the DirEttore software based on a directory structure."; app.ExtendedHelpText = $"{Environment.NewLine}This app can generate playlists for the DirEttore software which observe a distance between artists and songs played.{Environment.NewLine}Only files with an .mp3 extension will be considered for the playlist."; app.HelpOption("-?|-h|--help"); app.VersionOption("-v|--version", () => { return(string.Format("Version {0}", Assembly.GetEntryAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion)); }); var musicDirectory = app.Option("-d|--directory <musicdirectory>", "Required, this needs to point to the directory that is being searched for mp3 files", CommandOptionType.SingleValue); var outputOption = app.Option("-o|--output <playlistoutput>", $"Optional, if specified this will be the file to which the new playlist will be written, needs to end in .dpl. If not specified a random file name will be generated.", CommandOptionType.SingleValue); var playListSizeOption = app.Option("-ps|--size <playlistsize>", $"Optional, this will determine the size of the playlist to generate, set to {DefaultPlaylistSize} by default.", CommandOptionType.SingleValue); var artistSongSpacingOption = app.Option("-as|--spacing <artistsongspacing>", $"Optional, this will determine the distance observed between artists and songs, set to {DefaultArtistSongSpacing} by default.", CommandOptionType.SingleValue); app.OnExecute(() => { // TODO: add sweepers directory option // TODO: add option to define pattern (JINGLE / SWEEPERS / MUSIC, etc.) var outputFileName = outputOption.HasValue() ? outputOption.Value() : $"{Path.GetFileNameWithoutExtension(Path.GetRandomFileName())}.dpl"; if (!musicDirectory.HasValue() || string.IsNullOrWhiteSpace(musicDirectory.Value())) { Console.Error.WriteLine("The directory from which songs are sourced needs to be specified."); app.ShowHint(); return(-1); } if (outputOption.HasValue() && Path.GetExtension(outputOption.Value()) != ".dpl") { Console.Error.WriteLine("The output filename needs to end in '.dpl'."); app.ShowHint(); return(-1); } int playListSize = DefaultPlaylistSize; if (playListSizeOption.HasValue() && !int.TryParse(playListSizeOption.Value(), out playListSize)) { Console.Error.WriteLine("Invalid playlist size specified."); app.ShowHint(); return(-1); } int artistSongSpacing = DefaultArtistSongSpacing; if (artistSongSpacingOption.HasValue() && !int.TryParse(artistSongSpacingOption.Value(), out artistSongSpacing)) { Console.Error.WriteLine("Invalid artist and song spacing specified."); app.ShowHint(); return(-1); } Console.WriteLine("Source of music files: {0}", musicDirectory.Value()); Console.WriteLine("Playlist to write to: {0}", outputFileName); Console.WriteLine("Searching for mp3 files..."); var allFiles = Directory.EnumerateFiles(musicDirectory.Value(), "*.mp3", SearchOption.AllDirectories).ToArray(); Console.WriteLine($"Found {allFiles.Length} to consider for playlist generation."); var songParser = new SongParser(); Console.WriteLine($"Splitting mp3 files into artist and song name..."); var songs = songParser.ParseSongs(allFiles); Console.WriteLine($"Generating playlist of size {playListSize} and not repeating artist or song name for the last {artistSongSpacing} songs."); var songPicker = new SongPicker(playListSize, artistSongSpacing); var pickedSongs = songPicker.PickSongs(songs); Console.WriteLine($"Saving {pickedSongs.Count} songs to directory {outputFileName}."); var enc1252 = CodePagesEncodingProvider.Instance.GetEncoding(1252); using (var writer = new StreamWriter(outputFileName, false, enc1252)) { var songPersister = new SongPersister(); songPersister.PersistSongs(writer, pickedSongs); } Console.WriteLine($"Saving finished."); return(0); }); try { Console.WriteLine("Executing Playlist generator..."); app.Execute(args); } catch (Exception ex) { Console.WriteLine(); Console.Error.WriteLine("ERROR: {0}", ex.Message); } }
public Transposer(SongParser parser) { _parser = parser; }
public void TestParseCreatesValidObjectWithMultipleWriters() { #region data = ... var data = @"- ""Hear my song, Violetta"" (uncredited) Written by Othmar Klose, Rudolph Lukesch and 'Harry S. Pepper' (qv) Performed by 'Carmen Silvera' (qv)"; #endregion IList<string> songDefinition = new List<string>(data.Split(new string[] { "\r\n" }, StringSplitOptions.None)); var expected = new Song { Title = "Hear my song, Violetta", Composer = "Othmar Klose, Rudolph Lukesch and Harry S. Pepper", Lyricist = "Othmar Klose, Rudolph Lukesch and Harry S. Pepper", Performer = "Carmen Silvera" }; var logger = new Mock<ILog>(); Song actual = new SongParser(logger.Object).Parse(songDefinition); Assert.AreEqual(expected, actual); }
// a method to parse all song files in directory private void Parse() { Debug.Log("Parsing."); DirectoryInfo _info = new DirectoryInfo(GameData.songDirectory); FileInfo[] _mnFiles = _info.GetFiles("*.mn", SearchOption.AllDirectories); Debug.Log("Parsing Directory: " + GameData.songDirectory + " | Amount: " + _mnFiles.Length); for (int i = 0; i < _mnFiles.Length; i++) { SongParser _parser = new SongParser(); Debug.Log("Full name: " + _mnFiles[i].FullName); SongParser.Metadata _songData = _parser.Parse(_mnFiles[i].FullName); audioStartTime = _songData.sampleStart; audioLength = _songData.sampleLength; if (!_songData.valid) { Debug.Log("Song data is not valid."); // song data isn't valid continue; } else { GameObject _songObj = (GameObject)Instantiate(songSelectionPrefab, songSelectionList.transform.position, Quaternion.identity); _songObj.GetComponentInChildren <TMP_Text>().text = _songData.title + " - " + _songData.artist; // _songObj.transform.parent = songSelectionList.transform; _songObj.transform.SetParent(songSelectionList.transform, false); _songObj.transform.localScale = new Vector3(1, 1, 1); // reset scale just in case scale changes // get access to button control Button _songButton = _songObj.GetComponentInChildren <Button>(); if (File.Exists(_songData.bannerPath)) { Texture2D texture = new Texture2D(766, 182); texture.LoadImage(File.ReadAllBytes(_songData.bannerPath)); Debug.Log(_songData.bannerPath); _songButton.image.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100.0f); } _songButton.onClick.AddListener(delegate { StartSong(_songData); }); EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerEnter; entry.callback.AddListener(eventData => { if (_songData.musicPath != currentSongPath) { StartCoroutine(PreviewTrack(_songData.musicPath)); } }); _songButton.GetComponent <EventTrigger>().triggers.Add(entry); // check if a highscore for this song exists // if not, create it if (!GameData.currentSavedData.highscores.ContainsKey(_songData.title)) { GameData.currentSavedData.highscores.Add(_songData.title, 0.0f); } _songObj.GetComponentInChildren <TMP_Text>().text += string.Format("{0}Highscore: {1}", '\n', GameData.currentSavedData.highscores[_songData.title]); } } }