Ejemplo n.º 1
0
        protected override DiscreteSignal Render(NoteSegment segment)
        {
            DiscreteSignal mainSignal = null;

            if (segment is PercussionNoteSegment percussionNoteSegment)
            {
                mainSignal = GetPercussionSignal(percussionNoteSegment.PercussionType, percussionNoteSegment.DurationSamples);
            }
            else if (segment is MelodicNoteSegment melodicNoteSegment)
            {
                // Combine a Sine wave and a Square wave
                mainSignal = SignalHelper.GetSine(melodicNoteSegment.Frequency, melodicNoteSegment.DurationSamples);
                mainSignal.CombineAdd(SignalHelper.GetSquare(melodicNoteSegment.Frequency, melodicNoteSegment.DurationSamples));
            }

            float velocityMultiplier = segment.Velocity / 127f; // Velocity ranges from 0 - 127

            // A simple way of doing an equalizer
            float balanceMultiplier = BalanceProvider.GetMultiplier(segment);

            // Scale the signals based on their velocity and balance multipliers
            mainSignal.Amplify(velocityMultiplier * balanceMultiplier);
            mainSignal.ApplyAdsr(AdsrEnvelopeProvider.CreateEnvelope(segment));

            return(mainSignal);
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public DiscreteSignal CreateEnvelope(NoteSegment segment)
        {
            var adsrParameters = MelodicAdsrParameters;

            if (segment is PercussionNoteSegment percussionNoteSegment)
            {
                adsrParameters = GetPercussionAdsrParameters(percussionNoteSegment.PercussionType);
            }

            return(SignalHelper.GetAdsrEnvelope(adsrParameters, segment.DurationSamples));
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public float GetMultiplier(NoteSegment noteSegment)
        {
            if (noteSegment is PercussionNoteSegment percussionNoteSegment)
            {
                return(GetPercussionMultiplier(percussionNoteSegment.PercussionType));
            }
            else if (noteSegment is MelodicNoteSegment melodicNoteSegment)
            {
                return(GetFrequencyMultiplier(melodicNoteSegment.Frequency));
            }

            return(DefaultMultiplier); // Default to a "non-modified" multiplier
        }
Ejemplo n.º 4
0
        public async Task <JsonResult> AddSegmentToNote([FromHeader] int accountId, [FromBody] NoteSegment segment)
        {
            var errorMessage = segment.ValidateBody();

            if (errorMessage)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Message = "Segment body is empty."
                }));
            }

            var(error, user) = await _userService.GetUserProfileByAccountId(accountId);

            if (error || user == null)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while getting data."
                }));
            }

            var hasAssociation = await _collaborationService.IsNoteAssociatedWithThisUser(segment.NoteId, user.Id, SharedEnums.Permissions.Edit);

            if (!hasAssociation.HasValue)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while getting data."
                }));
            }
            if (!hasAssociation.Value)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Message = "You are not authorized for this action."
                }));
            }

            var saveResult = await _noteService.InsertNoteSegment(segment);

            return(!saveResult.HasValue || saveResult.Value < 1
                ? new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while saving data."
            })
                : new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Success, Data = saveResult.Value
            }));
        }
Ejemplo n.º 5
0
        public async Task <bool> UpdateNoteSegment(NoteSegment noteSegment)
        {
            try {
                _dbContext.NoteSegments.Update(noteSegment);
                var result = await _dbContext.SaveChangesAsync();

                return(result != 0);
            }
            catch (DbUpdateException e) {
                await _coreLogService.InsertRoutinizeCoreLog(new RoutinizeCoreLog {
                    Location            = $"{ nameof(NoteService) }.{ nameof(UpdateNoteSegment) }",
                    Caller              = $"{ new StackTrace().GetFrame(4)?.GetMethod()?.DeclaringType?.FullName }",
                    BriefInformation    = nameof(DbUpdateException),
                    DetailedInformation = $"Error while updating NoteSegment.\n\n{ e.StackTrace }",
                    ParamData           = $"{ nameof(noteSegment) } = { JsonConvert.SerializeObject(noteSegment) }",
                    Severity            = SharedEnums.LogSeverity.High.GetEnumValue()
                });

                return(false);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// The logic to turn NoteSegments into DiscreteSignals
 /// </summary>
 /// <param name="segment"></param>
 /// <returns></returns>
 protected abstract DiscreteSignal Render(NoteSegment segment);