1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
use crate::key::Key;
use crate::mode::Mode;
use crate::score::Score;

/// # TrackEntity
///
/// 楽曲の情報や性質をもつ
///
/// ### NOTE
///  * 要素を持ちすぎなので削れないか考える
///  * Entityである必要が今のところないのではないか
#[derive(Debug, Clone)]
pub struct TrackEntity {
    /// TrackID
    pub id: String,
    /// Track名
    pub title: String,
    /// アーティスト名
    pub artist: String,
    /// Track画像URL
    pub image: String,
    /// モード(旋法)
    pub mode: Mode,
    /// キー
    pub key: Key,
    /// BPM
    pub bpm: f32,
    /// 再生時間(秒)
    pub time: u64,
    /// 人気度
    pub popularity: Score,
    /// 踊りやすさ
    pub danceability: Score,
    /// エネルギー
    pub energy: Score,
    /// ポジティブ度
    pub valence: Score,
    /// アコースティック度
    pub acousticness: Score,
    /// インストゥルメンタル
    pub instrumentalness: Score,
    /// ライブ感
    pub liveness: Score,
    /// ポエトリー
    pub speechiness: Score,
}

impl TrackEntity {
    pub fn from(
        id: String,
        title: String,
        artist: String,
        image: String,
        mode: Mode,
        key: Key,
        bpm: f32,
        time: u64,
        popularity: Score,
        danceability: Score,
        energy: Score,
        valence: Score,
        acousticness: Score,
        instrumentalness: Score,
        liveness: Score,
        speechiness: Score,
    ) -> Self {
        Self {
            id,
            title,
            artist,
            image,
            mode,
            key,
            bpm,
            time,
            popularity,
            danceability,
            energy,
            valence,
            acousticness,
            instrumentalness,
            liveness,
            speechiness,
        }
    }

    /// このTrackがライブ音源かどうかを返す
    /// * true:  ライブ音源
    /// * false: スタジオ音源
    pub fn is_live(&self) -> bool {
        let live = match Score::try_from(80) {
            Ok(t) => t,
            Err(_) => return false,
        };
        self.liveness >= live
    }

    /// このTrackがスピーチかどうかを返す
    /// * true:  スピーチ
    /// * false: スピーチではない
    pub fn is_speech(&self) -> bool {
        let live = match Score::try_from(33) {
            Ok(t) => t,
            Err(_) => return false,
        };
        self.speechiness >= live
    }
}