private Common.Models.Rest GetRest(Rest rest) { if (int.TryParse(rest.Value.TrimStart('r'), out var duration)) { return(new Common.Models.Rest(DurationUtils.GetClosestDuration(duration))); } return(null); }
private void SetBarlineProgress(double duration, int dots) { _progress -= DurationUtils.GetProgressDuration((double)_lastTimeSignature.Beat / duration, dots); if (_progress <= 0) { _output += $" |\n{new string(' ', _scopes * SPACES_IN_TAB)}"; _progress = _lastTimeSignature.Ticks; } }
private IList <MetaSymbolGroup> GetMetadataFromTrack(Track track) { var symbolGroups = new List <MetaSymbolGroup>(); MetaSymbolGroup last = null; foreach (var e in track.Iterator()) { var message = e.MidiMessage; if (message.MessageType != MessageType.Meta) { continue; } var metaMessage = message as MetaMessage; switch (metaMessage?.MetaType) { case MetaType.TimeSignature: if (last != null) { last.End = e.AbsoluteTicks; } var timeSignatureBytes = metaMessage.GetBytes(); var beat = 1 / Math.Pow(timeSignatureBytes[1], -2); var symbolGroup = new SymbolGroup { Meter = new TimeSignature { Ticks = timeSignatureBytes[0], Beat = DurationUtils.GetClosestDuration(beat) } }; var meta = new MetaSymbolGroup { Start = e.AbsoluteTicks, SymbolGroup = symbolGroup }; symbolGroups.Add(meta); last = meta; _currentTimeSignature = symbolGroup.Meter; break; case MetaType.Tempo: var tempoBytes = metaMessage.GetBytes(); var tempo = (tempoBytes[0] & 0xff) << 16 | (tempoBytes[1] & 0xff) << 8 | (tempoBytes[2] & 0xff); last.SymbolGroup.Tempo = 60000000 / tempo; // bpm break; } } return(symbolGroups); }
public void AuthenticateCommand_AuthUser_SuccessAuth() { // ---- Arrange ---- const string email = "*****@*****.**"; const string name = "Test user"; const string password = "******"; var passwordHash = AuthUtils.GetMd5Hash(password); var clock = new FakeClock(SystemClock.Instance.GetCurrentInstant()); var testUser = new UserIdentityModel( Guid.NewGuid(), email, name, "user", passwordHash, clock.GetCurrentInstant()); _authRepositoryMock.Setup(r => r.GetUserIdentity(email)) .ReturnsAsync(() => testUser); var command = new AuthenticateUserCommand(email, password); var handler = new AuthenticateUserCommandHandler(_repositoryProviderMock.Object, _configuration) { Clock = clock }; AuthAccessModel result = null; var lifetime = DurationUtils.FromString( _configuration[$"{AuthUtils.Jwt.ConfigKeys.Section}:{AuthUtils.Jwt.ConfigKeys.LifetimeKey}"]); // ---- Act ---- Assert.DoesNotThrowAsync(async() => { result = await handler.Handle(command, CancellationToken.None); }); clock.Advance(lifetime); // for check expires token instant // ---- Assert ---- Assert.IsNotNull(result); Assert.AreEqual(testUser.Id, result.Id); Assert.AreEqual(testUser.Email, result.Email); Assert.AreEqual(clock.GetCurrentInstant(), result.ExpiresAt); Assert.AreEqual(clock.GetCurrentInstant(), result.ExpiresAt); Assert.AreEqual("user", testUser.Role); Assert.IsNotEmpty(result.Token); _authRepositoryMock.Verify(r => r.GetUserIdentity(email), Times.Once); }
public IList <MusicalSymbol> Build() { double progress = _meter.Ticks; // set progress to ticks, e.g. 4 foreach (var symbol in _notes) { if (symbol is PSAMNote note) { var duration = DurationUtils.GetProgressDuration((double)_meter.Beat / (double)note.Duration, note.NumberOfDots); progress -= duration; // subtract duration from progress } if (symbol is PSAMRest rest) { var duration = DurationUtils.GetProgressDuration((double)_meter.Beat / (double)rest.Duration, rest.NumberOfDots); progress -= duration; // subtract duration from progress } if (progress == 0) // Bar is full add symbol, then barline. Reset the progress { _symbols.Add(symbol); _symbols.Add(new Barline()); progress = _meter.Ticks; } else if (progress < 0) // Symbol won't fit in the bar. Add barline then symbol. Reset progress with remaining number. { _symbols.Add(new Barline()); _symbols.Add(symbol); progress = progress + _meter.Ticks; } else { _symbols.Add(symbol); // Add symbol } } _notes = new List <MusicalSymbol>(); return(_symbols); }
private void SetTimeSignature(string value) { var values = value.Split('/'); if (!int.TryParse(values[0], out var ticks) || !int.TryParse(values[1], out var beat)) { return; } _lastTimeSignature = new TimeSignature { Ticks = ticks, Beat = DurationUtils.GetClosestDuration(beat) }; if (_currentGroup.Symbols.Count == 0) // still empty { _currentGroup.Meter = _lastTimeSignature; return; } CreateNewSymbolGroup(); }
private Common.Models.Note GetNote(Note note) { var name = Regex.Replace(note.Value, @"[\d',.]", string.Empty); int.TryParse(Regex.Replace(note.Value, @"[A-Za-z',.]", string.Empty), out var duration); AlterOctave(note.Value); // set previous to the new note _previous = new Common.Models.Note((Names)name[0], _relativeOctave, DurationUtils.GetClosestDuration(duration)); if (name.EndsWith("es") || name.EndsWith("as")) { _previous.Modifier = Common.Definitions.Modifiers.Flat; } else if (name.EndsWith("is")) { _previous.Modifier = Common.Definitions.Modifiers.Sharp; } _previous.Dots = note.Value.ToCharArray().Count(dot => dot == '.'); return(_previous); }
private Duration GetJwtLifetime() { var lifetimeString = _configuration[AuthUtils.Jwt.ConfigKeys.LifetimeKey]; return(DurationUtils.FromString(lifetimeString)); }