public void Compose_3Animals_3ValidVersesAreReturned() { ISongWriter songWriter = new SongWriter(); string lyrics = songWriter.Compose(new Animal[] { new Lamb(), new Animal("donkey", "bray"), new Pig() }); string expectedLyrics = @" Old MacDonald had a farm, E - I - E - I - O, And on his farm he had a lamb, E - I - E - I - O. With a baa baa here and a baa baa there, Here a baa, there a baa, ev'rywhere a baa baa. Old MacDonald had a farm, E - I - E - I - O. Old MacDonald had a farm, E - I - E - I - O, And on his farm he had a donkey, E - I - E - I - O. With a bray bray here and a bray bray there, Here a bray, there a bray, ev'rywhere a bray bray. Old MacDonald had a farm, E - I - E - I - O. Old MacDonald had a farm, E - I - E - I - O, And on his farm he had a pig, E - I - E - I - O. With an oink oink here and an oink oink there, Here an oink, there an oink, ev'rywhere an oink oink. Old MacDonald had a farm, E - I - E - I - O. "; Assert.Equal(expectedLyrics, lyrics); }
public void Compose_2Animals_2ValidVersesAreReturned() { ISongWriter songWriter = new SongWriter(); string lyrics = songWriter.Compose(new Animal[] { new Horse(), new Pig() }); string expectedLyrics = @" Old MacDonald had a farm, E - I - E - I - O, And on his farm he had a horse, E - I - E - I - O. With a neigh neigh here and a neigh neigh there, Here a neigh, there a neigh, ev'rywhere a neigh neigh. Old MacDonald had a farm, E - I - E - I - O. Old MacDonald had a farm, E - I - E - I - O, And on his farm he had a pig, E - I - E - I - O. With an oink oink here and an oink oink there, Here an oink, there an oink, ev'rywhere an oink oink. Old MacDonald had a farm, E - I - E - I - O. "; Assert.Equal(expectedLyrics, lyrics); }
public void Compose_AnimalsEmpty_EmptyStringIsReturned() { ISongWriter songWriter = new SongWriter(); string lyrics = songWriter.Compose(new List <Animal>()); Assert.Equal(string.Empty, lyrics); }
public void Compose_AnimalsContainsNull_ThrowsException() { ISongWriter songWriter = new SongWriter(); var ex = Assert.Throws <SongException>(() => songWriter.Compose(new Animal[] { new Cow(), null, new Duck() })); Assert.Equal("Uninitialized animal object found.", ex.Message); }
/// <summary> /// Records the song. /// </summary> private IEnumerator Record() { // Debug.Log("Recording begun."); noteData = new SongParser.NoteData(); noteData.bars = new List <List <SongParser.Notes> >(); while (audioSource.isPlaying) { // float _timeOffset = 10.0f / (noteSpeed / Time.deltaTime); // songTimer = audioSource.time; //if (!canRecord && songTimer - _timeOffset >= (barExecutedTime - barTime)) //{ // canRecord = true; //} // Debug.Log(songTimer - _timeOffset); //if (!isRecordingBar && (songTimer - _timeOffset >= (barExecutedTime - barTime))) //{ // Debug.Log((songTimer - _timeOffset) + " >= " + (barExecutedTime - barTime)); // StartCoroutine(RecordBar()); // barExecutedTime += barTime; //} if (!isRecordingBar) { StartCoroutine(RecordBar()); } yield return(null); } songData.noteData = this.noteData; SongWriter _songWriter = new SongWriter(); _songWriter.Write(songData, targetPath); promptText.text = "RECORDING FINISHED"; yield break; }
public static Value Sound(Interpreter interpreter, List <Value> args) { if (!(args.Count == 3 || (args.Count % 4 == 0))) { interpreter.Error("Expected 3 Arguments or arguments in multiples of 4"); } if (interpreter.WaveOut != null) { if (interpreter.Exit) { interpreter.WaveOut?.Stop(); interpreter.WaveOut = null; interpreter.AudioQueue.Clear(); return(Value.Zero); } for (int index = 0; index < args.Count; index += 4) { interpreter.AudioQueue.Enqueue(new Note { Frequency = args[index].Real, Amplitude = args[index + 1].Real, Duration = (int)args[index + 2].Real, SignalType = args.Count == 3?DefaultSignalType: GetSignalType(args[index + 3].Real) }); } } else { using (var stream = new MemoryStream()) { using (var writer = new SongWriter(stream, 60, false)) { for (int index = 0; index < args.Count; index += 4) { writer.AddNote((float)args[index].Real, args[index + 2].Real / 1000, (short)(Math.Max(Math.Min((int)args[index + 1].Real, 16384), 0) / 16384 * short.MaxValue), args.Count == 3 ? DefaultSignalType : GetSignalType(args[index + 3].Real)); } } stream.Position = 0; interpreter.WaveOut = SoundEffect.FromStream(stream).CreateInstance(); interpreter.WaveOut.Play(); } } return(new Value(interpreter.AudioQueue.Count)); }
private void InitializeAndRunRhymeGenerator( string inputFilePath, string outputFilePath) { IIOService ioService = new ConsoleService(); IValidator validator = new Validator(new ValidatorSettings()); ISongWriter songWriter = new SongWriter(); IRhymeGenerator rhymeGenerator = new RhymeGenerator(ioService, validator, songWriter); using (StreamReader reader = new StreamReader(inputFilePath)) { using (StreamWriter writer = new StreamWriter(outputFilePath)) { ioService.SetIn(reader); ioService.SetOut(writer); rhymeGenerator.Run(); } } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space)) { SongParser.Metadata _tempSongData = new SongParser.Metadata(); _tempSongData.title = "JOURNEI"; _tempSongData.subtitle = ""; _tempSongData.artist = "Hans"; _tempSongData.bannerPath = ""; _tempSongData.backgroundPath = ""; _tempSongData.musicPath = "JOURNEI.mp3"; _tempSongData.offset = 0.0f; _tempSongData.sampleStart = 97.33f; _tempSongData.sampleLength = 10.58f; _tempSongData.bpm = 125; SongParser.NoteData _tempNoteData = new SongParser.NoteData(); List <SongParser.Notes> _tempBar = new List <SongParser.Notes>(); SongParser.Notes _tempNotes = new SongParser.Notes(); _tempNotes.bottom = 0; _tempNotes.middle = SongParser.NoteType.Air; _tempNotes.top = 0; _tempBar.Add(_tempNotes); _tempNoteData.bars = new List <List <SongParser.Notes> >(); _tempNoteData.bars.Add(_tempBar); _tempSongData.noteData = _tempNoteData; SongWriter _songWriter = new SongWriter(); _songWriter.Write(_tempSongData, Application.persistentDataPath); Debug.Log("Song should be written now."); } }
public static void SetWriterInstance(SongWriter writer) { writerInstance = writer; }
public void SaveLibrary(SongWriter writer) { writer.Write(library.Songs); }