bms-utils 0.2.1

BMSのファイル(.bms .bme .bml .pms .bmson)に関するライブラリ Library for BMS files. (.bms .bme .bml .pms .bmson)
Documentation
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
pub(crate) mod lex;
pub(crate) mod parse;
pub(crate) mod token;
pub use token::Channel;

/// ファイルを解析したままのBMS
///
/// ランダム要素を確定していない。
/// [`RawBms::make_bms`]で疑似乱数生成器を指定してBMSを生成する
#[derive(Debug, Clone, PartialEq, Default)]
pub struct RawBms {
    raw_bms: BmsBlock,
    all_wav_files: HashSet<String>,
}

#[derive(Debug, Clone, PartialEq, Default)]
pub(crate) struct BmsBlock(Vec<BmsElement>);
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum BmsElement {
    Command(token::Command),
    Random(BmsRandomBlock),
    Switch(BmsSwitchBlock),
}
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct BmsRandomBlock(RandomValue, Vec<BmsRandomElement>);
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum BmsRandomElement {
    Block(BmsBlock),
    IfBlock(BmsIfBlock),
}
#[derive(Debug, Clone, Default, PartialEq)]
pub(crate) struct BmsIfBlock {
    pub(crate) r#if: Vec<(u128, BmsBlock)>,
    pub(crate) r#else: Option<BmsBlock>,
}
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct BmsSwitchBlock(
    RandomValue,
    Vec<BmsCaseBlock>,
    std::collections::HashSet<u128>,
);
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct BmsCaseBlock(SwitchLabel, BmsBlock, bool);
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum RandomValue {
    Max(u128),
    Set(u128),
}
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum SwitchLabel {
    Case(u128),
    Default,
}
impl BmsBlock {
    pub(crate) fn get_token_vec<'a, Rng: rand::RngCore>(
        &'a self,
        output: &mut Vec<&'a token::Command>,
        rng: &mut Rng,
    ) {
        for e in &self.0 {
            e.get_token_vec(output, rng);
        }
    }
}
impl BmsElement {
    fn get_token_vec<'a, Rng: rand::RngCore>(
        &'a self,
        output: &mut Vec<&'a token::Command>,
        rng: &mut Rng,
    ) {
        match self {
            BmsElement::Command(c) => {
                output.push(c);
            }
            BmsElement::Random(rb) => {
                rb.get_token_vec(output, rng);
            }
            BmsElement::Switch(sb) => {
                sb.get_token_vec(output, rng);
            }
        }
    }
}
impl BmsRandomBlock {
    fn get_token_vec<'a, Rng: rand::RngCore>(
        &'a self,
        output: &mut Vec<&'a token::Command>,
        rng: &mut Rng,
    ) {
        use rand::Rng;
        let n = match self.0 {
            RandomValue::Max(n) => rng.random_range(1..=n),
            RandomValue::Set(n) => n,
        };
        for e in &self.1 {
            e.get_token_vec(output, rng, n);
        }
    }
}
impl BmsRandomElement {
    fn get_token_vec<'a, Rng: rand::RngCore>(
        &'a self,
        output: &mut Vec<&'a token::Command>,
        rng: &mut Rng,
        n: u128,
    ) {
        match self {
            BmsRandomElement::Block(b) => {
                b.get_token_vec(output, rng);
            }
            BmsRandomElement::IfBlock(ib) => {
                ib.get_token_vec(output, rng, n);
            }
        }
    }
}
impl BmsIfBlock {
    fn get_token_vec<'a, Rng: rand::RngCore>(
        &'a self,
        output: &mut Vec<&'a token::Command>,
        rng: &mut Rng,
        n: u128,
    ) {
        for (i, b) in &self.r#if {
            if *i == n {
                b.get_token_vec(output, rng);
                return;
            }
        }
        if let Some(b) = &self.r#else {
            b.get_token_vec(output, rng);
        }
    }
}
impl BmsSwitchBlock {
    fn get_token_vec<'a, Rng: rand::RngCore>(
        &'a self,
        output: &mut Vec<&'a token::Command>,
        rng: &mut Rng,
    ) {
        use rand::Rng;
        let n = match self.0 {
            RandomValue::Max(n) => rng.random_range(1..=n),
            RandomValue::Set(n) => n,
        };
        let mut flag = false;
        for e in &self.1 {
            if match &e.0 {
                SwitchLabel::Case(i) => *i == n,
                SwitchLabel::Default => !self.2.contains(&n),
            } {
                flag = true;
            }
            if flag {
                e.1.get_token_vec(output, rng);
            }
            if flag && e.2 {
                return;
            }
        }
    }
}

use std::collections::{HashMap, HashSet};
impl RawBms {
    pub fn parse(source: &str) -> RawBms {
        use token::*;
        use winnow::prelude::*;
        let token_stream = lex::lex(source);
        let all_wav_files = token_stream
            .iter()
            .filter_map(|t| {
                if let Token::Command(Command::Wav(_, file)) = t {
                    Some(file.clone())
                }
                else {
                    None
                }
            })
            .collect::<HashSet<_>>();
        RawBms {
            raw_bms: parse::block
                .parse_next(&mut token_stream.as_slice())
                .unwrap(),
            all_wav_files,
        }
    }
    pub fn all_wav_files(&self) -> &HashSet<String> {
        &self.all_wav_files
    }
    #[allow(deprecated)]
    pub fn make_bms(&self, mut rng: impl rand::RngCore) -> Bms<'_> {
        use token::Command::*;
        let mut commands = vec![];
        self.raw_bms.get_token_vec(&mut commands, &mut rng);

        let base62 = commands.iter().any(|c| matches!(c, Base62));

        let mut bms = Bms {
            main_data: Vec::with_capacity(1000),
            ..Default::default()
        };

        let convert_channel_vec = |ch_vec: &[Channel]| {
            ch_vec
                .iter()
                .map(|ch| ch.to_base_36_or_62(base62))
                .collect::<Vec<_>>()
        };
        for c in commands {
            match c {
                MainData(measure, data) => {
                    if bms.main_data.len() <= *measure {
                        bms.main_data
                            .resize_with(measure + 1, Default::default);
                    }
                    let measure = &mut bms.main_data[*measure];
                    use token::MainDataValue::*;
                    #[rustfmt::skip]
                    match data {
                        Bgm(data) =>
                            measure.bgm.push(convert_channel_vec(data)),
                        Length(n) =>
                            measure.length = *n,
                        Bga(data) =>
                            measure.bga.push(convert_channel_vec(data)),
                        Bpm(data) =>
                            measure.bpm.push(data),
                        BgaPoor(data) =>
                            measure.bga_poor.push(convert_channel_vec(data)),
                        BgaLayer(data) =>
                            measure.bga_layer.push(convert_channel_vec(data)),
                        ExBpm(data) =>
                            measure.ex_bpm.push(convert_channel_vec(data)),
                        Stop(data) =>
                            measure.stop.push(convert_channel_vec(data)),
                        BgaLayer2(data) =>
                            measure.bga_layer2.push(convert_channel_vec(data)),
                        ExRank(data) =>
                            measure.ex_rank.push(convert_channel_vec(data)),
                        BgaAlpha(data) =>
                            measure.bga_alpha.push(data),
                        BgaLayerAlpha(data) =>
                            measure.bga_layer_alpha.push(data),
                        BgaLayer2Alpha(data) =>
                            measure.bga_layer2_alpha.push(data),
                        BgaPoorAlpha(data) =>
                            measure.bga_poor_alpha.push(data),
                        Note(ch, data) =>
                            measure.notes.entry(*ch).or_default().push(convert_channel_vec(data)),
                        InvisibleNote(ch, data) =>
                            measure.invisible_notes.entry(*ch).or_default().push(convert_channel_vec(data)),
                        LongNote(ch, data) =>
                            measure.long_notes.entry(*ch).or_default().push(convert_channel_vec(data)),
                        Text(data) =>
                            measure.text.push(convert_channel_vec(data)),
                        BgaArgb(data) =>
                            measure.bga_argb.push(convert_channel_vec(data)),
                        BgaLayerArgb(data) =>
                            measure.bga_layer_argb.push(convert_channel_vec(data)),
                        BgaLayer2Argb(data) =>
                            measure.bga_layer2_argb.push(convert_channel_vec(data)),
                        BgaPoorArgb(data) =>
                            measure.bga_poor_argb.push(convert_channel_vec(data)),
                        SwitchBga(data) =>
                            measure.switch_bga.push(convert_channel_vec(data)),
                        Option(data) =>
                            measure.option.push(convert_channel_vec(data)),
                        Landmine(ch, data) =>
                            measure.landmine.entry(*ch).or_default().push(data),
                        Scroll(data) =>
                            measure.scroll.push(convert_channel_vec(data)),
                        Speed(data) =>
                            measure.speed.push(convert_channel_vec(data)),
                        Other(ch, data) =>
                            measure.other.push((*ch, data)),
                    };
                }
                Player(n) => {
                    bms.player = Some(match n {
                        1 => PlayType::SinglePlay,
                        2 => PlayType::CouplePlay,
                        3 => PlayType::DoublePlay,
                        4 => PlayType::BattlePlay,
                        _ => unreachable!(),
                    });
                }
                Rank(n) => bms.rank = Some(*n),
                DefExRank(n) => bms.def_ex_rank = Some(*n),
                ExRank(ch, n) => {
                    bms.ex_rank.insert(ch.to_base_36_or_62(base62), *n);
                }
                Total(n) => bms.total = Some(*n),
                VolumeWav(n) => bms.volume_wav = Some(*n),
                StageFile(s) => bms.stage_file = Some(s),
                Banner(s) => bms.banner = Some(s),
                BackBmp(s) => bms.back_bmp = Some(s),
                CharacterFile(s) => bms.character_file = Some(s),
                PlayLevel(n) => bms.play_level = Some(*n),
                Difficulty(n) => bms.difficulty = Some(*n),
                Title(s) => bms.title = Some(s),
                SubTitle(s) => bms.sub_title.push(s),
                Artist(s) => bms.artist = Some(s),
                SubArtist(s) => bms.sub_artist.push(s),
                Maker(s) => bms.maker = Some(s),
                Genre(s) => bms.genre = Some(s),
                Comment(s) => bms.comment.push(s),
                Text(ch, s) => {
                    bms.text.insert(ch.to_base_36_or_62(base62), s);
                }
                PathWav(s) => bms.path_wav = Some(s),
                Bpm(n) => bms.bpm = Some(*n),
                ExBpm(ch, n) => {
                    bms.ex_bpm.insert(ch.to_base_36_or_62(base62), *n);
                }
                BaseBpm(n) => bms.base_bpm = Some(*n),
                Stop(ch, n) => {
                    bms.stop.insert(ch.to_base_36_or_62(base62), *n);
                }
                Stp(x, y, z) => bms.stp.push((*x, *y, *z)),
                LnMode(n) => bms.ln_mode = Some(*n),
                LnType(n) => bms.ln_type = Some(*n),
                LnObject(ch) => {
                    bms.ln_object.insert(ch.to_base_36_or_62(base62));
                }
                OctFp => bms.oct_fp = true,
                Option(opt) => bms.option.push(opt),
                ChangeOption(ch, opt) => {
                    bms.change_option.insert(ch.to_base_36_or_62(base62), opt);
                }
                Wav(ch, s) => {
                    bms.wav.insert(ch.to_base_36_or_62(base62), s);
                }
                WavCommand(opt, ch, v) => {
                    bms.wav_command.push((
                        *opt,
                        ch.to_base_36_or_62(base62),
                        *v,
                    ));
                }
                ExWav(ch, opt, s) => {
                    bms.ex_wav.insert(ch.to_base_36_or_62(base62), (opt, s));
                }
                Cdda(n) => bms.cdda = Some(*n),
                MidiFile(s) => bms.midi_file = Some(s),
                Bmp(ch, s) => {
                    bms.bmp.insert(ch.to_base_36_or_62(base62), s);
                }
                ExBmp(ch, argb, s) => {
                    bms.ex_bmp.insert(ch.to_base_36_or_62(base62), (argb, s));
                }
                Bga(ch, bmp, pos) => {
                    bms.bga.insert(
                        ch.to_base_36_or_62(base62),
                        (bmp.to_base_36_or_62(base62), pos),
                    );
                }
                AtBga(ch, bmp, pos) => {
                    bms.at_bga.insert(
                        ch.to_base_36_or_62(base62),
                        (bmp.to_base_36_or_62(base62), pos),
                    );
                }
                PoorBga(n) => bms.poor_bga = Some(*n),
                SwitchBga(ch, fr, time, line, r#loop, argb, data) => {
                    bms.switch_bga.insert(
                        ch.to_base_36_or_62(base62),
                        (*fr, *time, line.to_base_36(), *r#loop, argb, data),
                    );
                }
                Argb(ch, argb) => {
                    bms.argb.insert(ch.to_base_36_or_62(base62), argb);
                }
                VideoFile(s) => bms.video_file = Some(s),
                VideoFps(n) => bms.video_fps = Some(*n),
                VideoColors(n) => bms.video_colors = Some(*n),
                VideoDelay(n) => bms.video_delay = Some(*n),
                Movie(s) => bms.movie = Some(s),
                Seek(ch, n) => {
                    bms.seek.insert(ch.to_base_36_or_62(base62), *n);
                }
                ExCharacter(sprite_num, bmp, trim_rect, offset, abs_pos) => {
                    bms.ex_character = Some(super::bms::ExCharacter {
                        sprite_num: *sprite_num,
                        bmp: *bmp,
                        trim_rect,
                        offset: offset.as_ref(),
                        abs_pos: abs_pos.as_ref(),
                    });
                }
                Url(s) => bms.url = Some(s),
                Email(s) => bms.email = Some(s),
                Scroll(ch, n) => {
                    bms.scroll.insert(ch.to_base_36_or_62(base62), *n);
                }
                Speed(ch, n) => {
                    bms.speed.insert(ch.to_base_36_or_62(base62), *n);
                }
                Preview(s) => bms.preview = Some(s),
                Other(command, value) => {
                    bms.other.push((command, value));
                }
                _ => (),
            }
        }
        bms
    }
}

/// ランダムを考慮したBMS
#[derive(Default, Debug, PartialEq)]
pub struct Bms<'a> {
    /// メインデータ
    ///
    /// mmmcc:chchch...
    ///
    /// mmm : 小節数 [0-9]
    ///
    /// cc : チャンネル [0-9, A-Z, a-z]
    ///
    /// chchch.. : メインのデータで、2文字一組として扱う [0-9, A-Z, a-z]
    pub main_data: Vec<MainData<'a>>,
    /// 判定幅
    ///
    /// 2を基本とするのが主流だが、その幅は実装依存
    pub rank: Option<i32>,
    /// より細かい判定幅
    ///
    /// 100をRank2と同じとするのが主流だが、
    /// Rankの1に相当する数が実装依存
    pub def_ex_rank: Option<f64>,
    /// ゲージ増加の総数
    ///
    /// 全て最良判定のときのゲージの増加量
    pub total: Option<f64>,
    /// 譜面全体の音量
    pub volume_wav: Option<f64>,
    /// ロード画面に表示する画像
    pub stage_file: Option<&'a str>,
    /// 選曲画面やリザルト画面に表示する横長の画像
    pub banner: Option<&'a str>,
    /// ステージファイルに重ねる画像
    ///
    /// 選曲後カバー等の調整をする画面で、
    /// ステージファイルにタイトルの代わりに重ねる
    pub back_bmp: Option<&'a str>,
    /// レベル
    pub play_level: Option<i32>,
    /// 難易度
    ///
    /// 主流な名付けは
    ///
    /// 1 : EASY, BEGINNER, LIGHT ...
    ///
    /// 2 : NORMAL, STANDARD ...
    ///
    /// 3 : HARD, HYPER ...
    ///
    /// 4 : EX, ANOTHER ...
    ///
    /// 5 : BLACK_ANOTHER, INSANE, 発狂 ...
    pub difficulty: Option<i32>,
    /// タイトル
    pub title: Option<&'a str>,
    /// サブタイトル
    pub sub_title: Vec<&'a str>,
    /// アーティスト
    pub artist: Option<&'a str>,
    /// サブアーティスト
    pub sub_artist: Vec<&'a str>,
    /// ジャンル名
    pub genre: Option<&'a str>,
    /// 基本BPM
    ///
    /// 曲選択時の表示や曲の最初のBPMとして使う
    pub bpm: Option<f64>,
    /// BPM変化用
    ///
    /// BPM変化時に256以上の値を指定したいとき、
    /// 08チャンネルでidを指定する
    pub ex_bpm: HashMap<usize, f64>,
    /// 停止
    ///
    /// 譜面を停止するときに09チャンネルでidを指定する
    pub stop: HashMap<usize, f64>,
    /// LNの判定方法
    ///
    /// 1 : LN, 始点判定が基準で、最後まで押し切らないとPOOR
    ///
    /// 2 : CN, 始点判定と終点判定がある
    ///
    /// 3 : HCN, CHの判定に、押している間16分ごとに判定を追加したもの
    pub ln_mode: Option<i32>,
    /// LNの指定方法
    ///
    /// 1 : 主流の指定方法
    ///
    /// メインデータの0以外のidをLNの始点終点の繰り返しとして解析
    ///
    /// 2 : 非推奨な指定方法
    ///
    /// メインデータの0以外のidが続く部分をLNとして解析
    ///
    ///    ///
    /// 1 : 0011000000002200
    ///
    /// 2 : 0011111111220000
    pub ln_type: Option<i32>,
    /// LNの音を鳴らす終点idの指定
    ///
    /// LNTYPE 1 で終点として使うと、音が鳴るようになる
    pub ln_object: HashSet<usize>,
    /// 音声ファイル
    ///
    /// 詳細はメインデータ等に記載
    pub wav: HashMap<usize, &'a str>,
    /// 画像ファイル
    ///
    /// 詳細はメインデータ等に記載
    pub bmp: HashMap<usize, &'a str>,
    /// BMS制作者のホームページ
    pub url: Option<&'a str>,
    /// BMS制作者のEメール
    pub email: Option<&'a str>,
    /// 譜面速度
    pub scroll: HashMap<usize, f64>,
    /// 譜面速度
    ///
    /// SCROLLと違って線形補間がされる
    pub speed: HashMap<usize, f64>,
    /// 曲選択時に流れる音声
    ///
    /// ここで指定されていなければ、
    /// previewと名前が付いた音声ファイルを流すのが主流
    pub preview: Option<&'a str>,

    // 以降あまり使われないコマンド
    /// メインデータで指定可能な判定幅の設定
    ///
    /// 値はDefExRankと同じ扱いをすることが主流だが、DefExRankと同じように判定幅が実装依存
    pub ex_rank: HashMap<usize, f64>,
    pub character_file: Option<&'a str>,
    /// 譜面制作者
    pub maker: Option<&'a str>,
    /// 曲選択時に表示するコメント
    pub comment: Vec<&'a str>,
    /// プレイ中に表示するテキスト
    pub text: HashMap<usize, &'a str>,
    /// 音声ファイルを読み込むときに参照するフォルダ
    pub path_wav: Option<&'a str>,
    /// 譜面の停止
    ///
    /// (小節数, 1000等分した小節内の位置, 停止ms)
    ///
    /// 位置が一致するコマンドが複数あったら停止時間は合計時間を参照する
    pub stp: Vec<(usize, u32, f64)>,
    /// オクターブモード / フットペダルモード
    pub oct_fp: bool,
    /// オプション適用
    pub option: Vec<&'a str>,
    /// オプション適用(譜面内で動的変更)
    ///
    /// チャンネルは"A6"
    pub change_option: HashMap<usize, &'a str>,
    /// WAVを加工する
    ///
    /// (ID, index, value)
    ///
    /// ID: 0.ピッチ 1.ボリューム 2.再生時間
    ///
    /// index: WAVコマンドのindex
    ///
    /// value: 0.基準は60で、1を半音と対応 1.パーセントで解釈 2.ミリ秒(0で変更なし)
    pub wav_command: Vec<(i32, usize, f64)>,
    pub ex_wav: HashMap<usize, (&'a [Option<f64>; 3], &'a str)>,
    pub cdda: Option<u32>,
    pub midi_file: Option<&'a str>,
    pub ex_bmp: HashMap<usize, (&'a [u8; 4], &'a str)>,
    pub bga: HashMap<usize, (usize, &'a [[f64; 2]; 3])>,
    pub at_bga: HashMap<usize, (usize, &'a [[f64; 2]; 3])>,
    pub poor_bga: Option<i32>,
    pub argb: HashMap<usize, &'a [u8; 4]>,
    pub video_file: Option<&'a str>,
    pub video_fps: Option<f64>,
    pub video_colors: Option<u32>,
    pub video_delay: Option<u32>,
    pub movie: Option<&'a str>,
    pub ex_character: Option<ExCharacter<'a>>,

    // 以降非推奨のコマンド
    /// プレイ方法
    ///
    /// 主にメインデータから解析するのが主流
    #[deprecated]
    pub player: Option<PlayType>,
    /// スクロール速度の基準BPM
    ///
    /// オプション側で基準とするBPMを最大、最小、最長、最初のBPMに合わせられるようにするべき
    #[deprecated]
    pub base_bpm: Option<f64>,
    /// キーを押したときに表示するBGA
    ///
    /// 試験的に追加された
    #[deprecated]
    pub switch_bga:
        HashMap<usize, (f64, f64, usize, bool, &'a [u8; 4], &'a [Channel])>,
    /// ビデオの再生位置を調整
    ///
    /// 提案されたプレイヤーで削除済み
    #[deprecated]
    pub seek: HashMap<usize, f64>,

    /// その他のコマンド
    pub other: Vec<(&'a str, &'a str)>,
}

/// 一小節ごとのメインデータ
///
/// 同じ小節、同じチャンネルが複数行定義された場合に対応
///
/// bgmとoptionのみ複数行に対応している場合が多い
#[derive(Debug, PartialEq)]
pub struct MainData<'a> {
    /// BGM
    pub bgm: Vec<Vec<usize>>,
    /// 一小節の長さ
    ///
    /// 1が基準
    pub length: f64,
    /// BPM
    ///
    /// 1から255まで
    pub bpm: Vec<&'a [Option<f64>]>,
    /// BGA
    pub bga: Vec<Vec<usize>>,
    /// POOR BGA
    pub bga_poor: Vec<Vec<usize>>,
    /// BGA LAYER
    pub bga_layer: Vec<Vec<usize>>,
    /// EXBPM
    pub ex_bpm: Vec<Vec<usize>>,
    /// 停止
    pub stop: Vec<Vec<usize>>,
    /// BGA LAYER2
    pub bga_layer2: Vec<Vec<usize>>,
    /// BGA不透明度
    pub bga_alpha: Vec<&'a [u8]>,
    /// BGA LAYER不透明度
    pub bga_layer_alpha: Vec<&'a [u8]>,
    /// BGA LAYER2不透明度
    pub bga_layer2_alpha: Vec<&'a [u8]>,
    /// POOR BGA不透明度
    pub bga_poor_alpha: Vec<&'a [u8]>,
    /// ノーツ
    ///
    /// チャンネルを36進数で解釈した値をキーにした`HashMap`
    pub notes: HashMap<usize, Vec<Vec<usize>>>,
    /// 不可視ノーツ
    ///
    /// チャンネルを36進数で解釈した値をキーにした`HashMap`
    pub invisible_notes: HashMap<usize, Vec<Vec<usize>>>,
    /// ロングノーツ
    ///
    /// チャンネルを36進数で解釈した値をキーにした`HashMap`
    pub long_notes: HashMap<usize, Vec<Vec<usize>>>,
    /// テキスト
    pub text: Vec<Vec<usize>>,
    /// EXRANK
    pub ex_rank: Vec<Vec<usize>>,
    /// BGA aRGB
    pub bga_argb: Vec<Vec<usize>>,
    /// BGA LAYER aRGB
    pub bga_layer_argb: Vec<Vec<usize>>,
    /// BGA LAYER2 aRGB
    pub bga_layer2_argb: Vec<Vec<usize>>,
    /// POOR BGA aRGB
    pub bga_poor_argb: Vec<Vec<usize>>,
    /// SWBGA
    pub switch_bga: Vec<Vec<usize>>,
    /// オプション
    pub option: Vec<Vec<usize>>,
    /// 地雷
    pub landmine: HashMap<usize, Vec<&'a [f64]>>,
    /// スクロール速度
    pub scroll: Vec<Vec<usize>>,
    /// ノーツ速度
    pub speed: Vec<Vec<usize>>,

    /// その他
    pub other: Vec<(usize, &'a str)>,
}
impl Default for MainData<'_> {
    fn default() -> Self {
        MainData {
            bgm: vec![],
            length: 1.0,
            bpm: vec![],
            bga: vec![],
            bga_poor: vec![],
            bga_layer: vec![],
            ex_bpm: vec![],
            stop: vec![],
            bga_layer2: vec![],
            bga_alpha: vec![],
            bga_layer_alpha: vec![],
            bga_layer2_alpha: vec![],
            bga_poor_alpha: vec![],
            notes: HashMap::new(),
            invisible_notes: HashMap::new(),
            long_notes: HashMap::new(),
            text: vec![],
            ex_rank: vec![],
            bga_argb: vec![],
            bga_layer_argb: vec![],
            bga_layer2_argb: vec![],
            bga_poor_argb: vec![],
            switch_bga: vec![],
            option: vec![],
            landmine: HashMap::new(),
            scroll: vec![],
            speed: vec![],
            other: vec![],
        }
    }
}

/// Extended-Characterファイル
#[derive(Debug, PartialEq)]
pub struct ExCharacter<'a> {
    pub sprite_num: u32,
    pub bmp: usize,
    pub trim_rect: &'a [[f64; 2]; 2],
    pub offset: Option<&'a [f64; 2]>,
    pub abs_pos: Option<&'a [f64; 2]>,
}

/// プレイ方式
#[derive(Debug, PartialEq)]
pub enum PlayType {
    SinglePlay,
    CouplePlay,
    DoublePlay,
    BattlePlay,
}