Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 0 additions & 104 deletions src/main/java/com/mr/domain/playing/entity/MidiEvent.java

This file was deleted.

84 changes: 84 additions & 0 deletions src/main/java/com/mr/domain/playing/entity/MidiEventData.java
Comment thread
on1yoneprivate marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.mr.domain.playing.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.mr.domain.playing.entity.enums.MidiType;
import com.mr.domain.playing.exception.PlayingErrorStatus;
import com.mr.global.apipayload.exception.GeneralException;
import lombok.Getter;

@Getter
public class MidiEventData {

// 동일 timestamp 내 순서 값
@JsonProperty("sequence")
private final Integer sequence;

private final MidiType type;
private final Integer pitch;
private final Integer velocity;

@JsonProperty("timestamp_ms")
private final Long timestampMs;

private MidiEventData(
Integer sequence,
MidiType type,
Integer pitch,
Integer velocity,
Long timestampMs
) {
validateSequence(sequence);
validateMidiType(type);
validatePitch(pitch);
validateVelocity(velocity);
Comment on lines +33 to +34

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MidiType을 지금 NOTE_ON, NOTE_OFF만 갖고 있는데 저희 MIDI 데이터를 요 정도만 받아도 되는 건지 궁금해요! (이건 PM님과 논의할 사안인 것 같지만....) 현재는 모든 타입에 pitch와 velocity를 필수로 검증하고 있어, 추후 페달이나 Control Change 이벤트까지 저장한다면 타입별 검증 또는 이벤트 모델 분리가 필요할 것 같아요!!

validateTimestampMs(timestampMs);

this.sequence = sequence;
this.type = type;
this.pitch = pitch;
this.velocity = velocity;
this.timestampMs = timestampMs;
}

@JsonCreator
public static MidiEventData of(
@JsonProperty("sequence") Integer sequence,
@JsonProperty("type") MidiType type,
@JsonProperty("pitch") Integer pitch,
@JsonProperty("velocity") Integer velocity,
@JsonProperty("timestamp_ms") Long timestampMs
) {
return new MidiEventData(sequence, type, pitch, velocity, timestampMs);
}

private static void validateSequence(Integer sequence) {
if (sequence == null || sequence < 0) {
throw new GeneralException(PlayingErrorStatus.INVALID_MIDI_SEQUENCE);
}
}

private static void validateMidiType(MidiType type) {
if (type == null) {
throw new GeneralException(PlayingErrorStatus.MISSING_MIDI_TYPE);
}
}

private static void validatePitch(Integer pitch) {
if (pitch == null || pitch < 0 || pitch > 127) {
throw new GeneralException(PlayingErrorStatus.INVALID_PITCH_RANGE);
}
}

private static void validateVelocity(Integer velocity) {
if (velocity == null || velocity < 0 || velocity > 127) {
throw new GeneralException(PlayingErrorStatus.INVALID_VELOCITY_RANGE);
}
}

private static void validateTimestampMs(Long timestampMs) {
if (timestampMs == null || timestampMs < 0) {
Comment thread
on1yoneprivate marked this conversation as resolved.
throw new GeneralException(PlayingErrorStatus.INVALID_TIMESTAMP);
}
}
}
Loading
Loading