private void HandleRest(MidiEvent midiEvent) { double lengthOfNote = CalculatePartOfBar(_previousNoteAbsoluteTicks, midiEvent.AbsoluteTicks); double availableLengthBar = EasyTimeSignature.Top - _notesOfBarReached; while (lengthOfNote > 0) { RestBuilder restBuilder = new RestBuilder(); // Get duration int duration; int dots; bool isTied; HandleDuration(lengthOfNote, availableLengthBar, out lengthOfNote, out availableLengthBar, out duration, out dots, out isTied); // Create rest and add restBuilder.Duration((DurationType)duration); restBuilder.IsDotted(dots); AddToPiece(restBuilder.Build()); // Check bar if (availableLengthBar == 0) { availableLengthBar = EasyTimeSignature.Top; } _notesOfBarReached = EasyTimeSignature.Top - availableLengthBar; } _previousNoteAbsoluteTicks = midiEvent.AbsoluteTicks; }
/// <summary> /// Creates a RestBuilder instance to build the connection command /// </summary> /// <param name="properties">Rest properties action</param> /// <returns></returns> public static RestBuilder Build(Action <RestProperties> properties) { RestBuilder restClient = new RestBuilder() { }; properties(restClient.Properties); return(restClient); }
private MusicElement CreateMusicElement(string token) { NoteType noteType; Enum.TryParse(token.Substring(0, 1).ToUpper(), out noteType); var dots = token.Count(c => c == '.'); var number = int.Parse(Regex.Match(token, @"\d+").Value); var durationType = (DurationType)number; if (new Regex(@"[a-g][,'eis]*[0-9]+[.]*").IsMatch(token)) { var builder = new NoteBuilder(noteType); // Octave var increaseOctaves = token.Count(c => c == '\''); var decreaseOctaves = token.Count(c => c == ',') * -1; builder.ChangeOctave(increaseOctaves + decreaseOctaves); // Sharp or flat if (token.Contains("is")) { builder = builder.Sharp(); } else if (token.Contains("token")) { builder = builder.Flat(); } if (token.Contains("~")) { builder = builder.IsTied(); } builder.AddDots(dots).Duration(durationType); return(builder.Build()); } if (new Regex(@"r.*?[0-9][.]*").IsMatch(token)) { var builder = new RestBuilder(); builder.AddDots(dots).Duration(durationType); return(builder.Build()); } return(null); }
private void RestSampleCode() { var serializer = new JsonSerializer(); var _builder = new RestBuilder("https://jsonplaceholder.typicode.com/users/1"); PostsRestClient client = new PostsRestClient(new CacheService(), serializer); var response = client.GetByID(1); CustomRestClient customRestClient = new CustomRestClient(new CacheService(), serializer, "https://jsonplaceholder.typicode.com/users/1"); var request = _builder .SetFormat(DataFormat.Json) .SetMethod(Method.GET) .Create(); var userResponse = customRestClient.Get <UserModel>(request); //serializer.Deserialize<> }