rgchart 0.0.13

A library for parsing and writing rhythm game charts.
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
746
747
748
749
750
use std::str::FromStr;
use std::ops::{Index, IndexMut};
use std::slice::SliceIndex;
use crate::models::osu::sound::HitSample;
use crate::models::common::{self, Key};
use crate::models::generic::sound::{self, SoundBank};
use crate::osu::OsuMode;

#[derive(Debug, Clone, PartialEq)]
pub struct HitObject {
    pub x: i32,
    
    pub y: i32,
    
    pub time: f32,
    
    pub object_type: u8,
    
    pub hit_sound: u8,
    
    pub object_params: Vec<String>,
    
    pub hit_sample: HitSample,
}

impl FromStr for HitObject {
    type Err = String;
    
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Self::from_str_with_mode(s, &OsuMode::Standard)
    }
}

impl Default for HitObject {
    fn default() -> Self {
        HitObject { x: 256, y: 192, time: 0.0, object_type: 1, hit_sound: 0, object_params: Vec::new(), hit_sample: HitSample::default() }
    }
}

impl HitObject {
    pub fn from_str_with_mode(s: &str, mode: &OsuMode) -> Result<Self, String> {
        let parts: Vec<&str> = s.split(',').collect();
        
        if parts.len() < 5 {
            return Err(format!("Expected at least 5 comma-separated values, found {}", parts.len()));
        }
        
        let x = parts[0].parse::<i32>()
            .map_err(|_| format!("Invalid x value: {}", parts[0]))?;
            
        let y = parts[1].parse::<i32>()
            .map_err(|_| format!("Invalid y value: {}", parts[1]))?;
            
        let time = parts[2].parse::<f32>()
            .map_err(|_| format!("Invalid time value: {}", parts[2]))?;
            
        let object_type = parts[3].parse::<u8>()
            .map_err(|_| format!("Invalid type value: {}", parts[3]))?;
            
        let hit_sound = parts[4].parse::<u8>()
            .map_err(|_| format!("Invalid hitSound value: {}", parts[4]))?;
        
        let mut object_params = Vec::new();
        let mut hit_sample = HitSample::default();
        
        if parts.len() > 5 {
            let is_mania_hold = matches!(mode, OsuMode::Mania) && (object_type & 128) != 0;
            
            if is_mania_hold {
                if parts.len() >= 6 {
                    let sixth_param = parts[5];
                    if sixth_param.contains(':') {
                        let param_parts: Vec<&str> = sixth_param.split(':').collect();
                        if !param_parts.is_empty() {
                            object_params.push(param_parts[0].to_string());
                            
                            if param_parts.len() > 1 {
                                let hit_sample_part = param_parts[1..].join(":");
                                hit_sample = HitSample::from_str(&hit_sample_part)?;
                            }
                        }
                    } else {
                        object_params.push(sixth_param.to_string());
                    }
                }
            } else {
                let last_part = parts[parts.len() - 1];
                if last_part.contains(':') {
                    hit_sample = HitSample::from_str(last_part)?;
                    object_params = parts[5..parts.len()-1].iter()
                        .map(|s| s.to_string())
                        .collect();
                } else {
                    object_params = parts[5..].iter()
                        .map(|s| s.to_string())
                        .collect();
                }
            }
        }
        
        Ok(HitObject {
            x,
            y,
            time,
            object_type,
            hit_sound,
            object_params,
            hit_sample,
        })
    }

    pub fn new(x: i32, y: i32, time: f32, object_type: u8, hit_sound: u8) -> Self {
        Self {
            x,
            y,
            time,
            object_type,
            hit_sound,
            object_params: Vec::new(),
            hit_sample: HitSample::default(),
        }
    }
    
    pub fn is_hit_circle(&self) -> bool {
        (self.object_type & 1) != 0
    }
    
    pub fn is_slider(&self) -> bool {
        (self.object_type & 2) != 0
    }
    
    pub fn is_new_combo(&self) -> bool {
        (self.object_type & 4) != 0
    }
    
    pub fn is_spinner(&self) -> bool {
        (self.object_type & 8) != 0
    }

    pub fn is_normal(&self) -> bool {
        (self.object_type & 1) == 1
    }
    
    pub fn is_hold(&self) -> bool {
        (self.object_type & 128) != 0
    }
    
    pub fn has_normal(&self) -> bool {
        (self.hit_sound & 1) != 0
    }
    
    pub fn has_whistle(&self) -> bool {
        (self.hit_sound & 2) != 0
    }
    
    pub fn has_finish(&self) -> bool {
        (self.hit_sound & 4) != 0
    }
    
    pub fn has_clap(&self) -> bool {
        (self.hit_sound & 8) != 0
    }

    pub fn combo_skip(&self) -> u8 {
        (self.object_type >> 4) & 7
    }
    
    pub fn end_time(&self) -> Option<i32> {
        if self.is_spinner() || self.is_hold() {
            if !self.object_params.is_empty() {
                return self.object_params[0].parse::<i32>().ok();
            }
        }
        None
    }
    
    pub fn slider_params(&self) -> Option<(String, Vec<String>, i32, f32)> {
        if self.is_slider() && self.object_params.len() >= 3 {
            let curve_info = &self.object_params[0];
            let curve_parts: Vec<&str> = curve_info.split('|').collect();
            
            if curve_parts.is_empty() {
                return None;
            }
            
            let curve_type = curve_parts[0].to_string();
            let curve_points: Vec<String> = curve_parts[1..].iter()
                .map(|s| s.to_string())
                .collect();
            
            let slides = self.object_params[1].parse::<i32>().ok()?;
            let length = self.object_params[2].parse::<f32>().ok()?;
            
            Some((curve_type, curve_points, slides, length))
        } else {
            None
        }
    }
    
    pub fn slider_edge_sounds(&self) -> Vec<i32> {
        if self.is_slider() && self.object_params.len() >= 4 {
            self.object_params[3]
                .split('|')
                .filter_map(|s| s.parse::<i32>().ok())
                .collect()
        } else {
            Vec::new()
        }
    }
    
    pub fn slider_edge_sets(&self) -> Vec<(i32, i32)> {
        if self.is_slider() && self.object_params.len() >= 5 {
            self.object_params[4]
                .split('|')
                .filter_map(|s| {
                    let parts: Vec<&str> = s.split(':').collect();
                    if parts.len() >= 2 {
                        let normal = parts[0].parse::<i32>().ok()?;
                        let addition = parts[1].parse::<i32>().ok()?;
                        Some((normal, addition))
                    } else {
                        None
                    }
                })
                .collect()
        } else {
            Vec::new()
        }
    }
    
    pub fn mania_column(&self, column_count: u8) -> u8 {
        let column = (self.x * (column_count as i32) / 512).max(0).min((column_count as i32) - 1);
        column as u8
    }
    
    pub fn to_taiko(&self) -> common::TaikoHitobject {
        use common::TaikoHitobject;
        
        let is_bonus = self.has_finish();
        let is_kat = self.has_whistle() || self.has_clap();
        let is_slider = self.is_slider();
        let is_spinner = self.is_spinner();
        
        match (is_slider, is_spinner, is_bonus, is_kat) {
            (true, _, true, _) => TaikoHitobject::bonus_drum_roll(self.end_time().unwrap_or(0)),
            (true, _, false, _) => TaikoHitobject::drum_roll(self.end_time().unwrap_or(0)),
            (_, true, _, _) => TaikoHitobject::balloon(self.end_time().unwrap_or(0)),
            (false, false, true, false) => TaikoHitobject::bonus_don(),
            (false, false, true, true) => TaikoHitobject::bonus_kat(),
            (false, false, false, false) => TaikoHitobject::don(),
            (false, false, false, true) => TaikoHitobject::kat(),
        }
    }
    
    pub fn to_catch(&self) -> common::CatchHitobject {
        use common::CatchHitobject;

        if self.is_hit_circle() {
            CatchHitobject::fruit(self.x)
        } else if self.is_slider() {
            CatchHitobject::juice(self.x)
        } else if self.is_spinner() {
            CatchHitobject::banana(self.x, self.end_time().unwrap_or(0))
        } else {
            CatchHitobject::empty()
        }
    }
    
    pub fn to_mania(&self, column_count: u8) -> (Key, u8) {
        let column = self.mania_column(column_count);
        let object_type = if self.is_normal() {
            Key::normal()
        } else if self.is_hold() {
            Key::slider_start(Some(self.end_time().unwrap_or(0)))
        } else {
            Key::empty()
        };
        
        (object_type, column)
    }

    pub fn get_generic_keysound(&self, soundbank: &mut SoundBank) -> sound::KeySound {
        let hitsound_type = match self.hit_sound {
            3 => sound::HitSoundType::Clap,
            1 => sound::HitSoundType::Whistle,
            2 => sound::HitSoundType::Finish,
            _ => sound::HitSoundType::Normal,
        };

        if self.hit_sample.filename.trim().is_empty() {
            sound::KeySound::of_type(100, hitsound_type)
        } else {
            let keysound_idx = soundbank.add_sound_sample(self.hit_sample.filename.clone());
            sound::KeySound::with_custom(self.hit_sample.volume.clamp(0, 100), keysound_idx, Some(hitsound_type))
        }
    }
    
    pub fn to_str(&self) -> String {
        let mut parts = vec![
            self.x.to_string(),
            self.y.to_string(),
            self.time.to_string(),
            self.object_type.to_string(),
            self.hit_sound.to_string(),
        ];
        
        parts.extend(self.object_params.iter().cloned());
        
        let hit_sample_str = self.hit_sample.to_str();
        parts.push(hit_sample_str);
        
        parts.join(",")
    }
}

impl HitObject {
    pub fn to_str_with_mode(&self, mode: &OsuMode, soundbank: Option<&mut SoundBank>) -> String {
        match mode {
            OsuMode::Standard => self.to_str_standard(),
            OsuMode::Taiko => self.to_str_taiko(),
            OsuMode::Catch => self.to_str_catch(),
            OsuMode::Mania => {
                if let Some(sb) = soundbank {
                    self.to_str_mania(sb)
                } else {
                    self.to_str_mania_no_soundbank()
                }
            },
            OsuMode::Unknown => self.to_str(),
        }
    }

    fn to_str_standard(&self) -> String {
        let mut parts = vec![
            self.x.to_string(),
            self.y.to_string(),
            self.time.to_string(),
            self.object_type.to_string(),
            self.hit_sound.to_string(),
        ];
        
        if self.is_slider() {
            parts.extend(self.object_params.iter().cloned());
        } else if self.is_spinner() {
            if let Some(end_time) = self.end_time() {
                parts.push(end_time.to_string());
            }
        }
        
        let hit_sample_str = self.hit_sample.to_str();
        parts.push(hit_sample_str);
        
        parts.join(",")
    }

    fn to_str_taiko(&self) -> String {
        let taiko_obj = self.to_taiko();
        let mut parts = vec![
            "256".to_string(),
            "192".to_string(),
            self.time.to_string(),
        ];

        match taiko_obj.note_type {
            common::TaikoHitobjectType::Don => {
                parts.push("1".to_string());
                parts.push("0".to_string());
            },
            common::TaikoHitobjectType::Kat => {
                parts.push("1".to_string());
                parts.push("2".to_string());
            },
            common::TaikoHitobjectType::BonusDon => {
                parts.push("1".to_string());
                parts.push("4".to_string());
            },
            common::TaikoHitobjectType::BonusKat => {
                parts.push("1".to_string());
                parts.push("6".to_string());
            },
            common::TaikoHitobjectType::DrumRoll => {
                parts.push("2".to_string());
                parts.push("0".to_string());
                let end_time = taiko_obj.end_time.unwrap_or(self.time as i32);
                parts.push(format!("L|256:192,1,{}", end_time - self.time as i32));
            },
            common::TaikoHitobjectType::BonusDrumRoll => {
                parts.push("2".to_string());
                parts.push("4".to_string());
                let end_time = taiko_obj.end_time.unwrap_or(self.time as i32);
                parts.push(format!("L|256:192,1,{}", end_time - self.time as i32));
            },
            common::TaikoHitobjectType::Balloon => {
                parts.push("8".to_string());
                parts.push("0".to_string());
                let end_time = taiko_obj.end_time.unwrap_or(self.time as i32);
                parts.push(end_time.to_string());
            },
            common::TaikoHitobjectType::Empty | common::TaikoHitobjectType::Unknown => {
                return String::new();
            }
        }

        let hit_sample_str = self.hit_sample.to_str();
        parts.push(hit_sample_str);

        return parts.join(",");
    }

    fn to_str_catch(&self) -> String {
        let catch_obj = self.to_catch();
        let mut parts = vec![
            self.x.to_string(),
            "192".to_string(),
            self.time.to_string(),
        ];

        match catch_obj.object_type {
            common::CatchHitobjectType::Fruit | common::CatchHitobjectType::Hyperfruit => {
                parts.push("1".to_string());
                parts.push(self.hit_sound.to_string());
            },
            common::CatchHitobjectType::Juice => {
                parts.push("2".to_string());
                parts.push(self.hit_sound.to_string());
                if !self.object_params.is_empty() {
                    parts.extend(self.object_params.iter().cloned());
                }
            },
            common::CatchHitobjectType::Banana => {
                parts.push("8".to_string());
                parts.push(self.hit_sound.to_string());
                parts.push(catch_obj.end_time().unwrap_or(0).to_string());
            },
            common::CatchHitobjectType::Empty | common::CatchHitobjectType::Unknown => {
                return String::new();
            },
        }

        let hit_sample_str = self.hit_sample.to_str();
        parts.push(hit_sample_str);

        parts.join(",")
    }

    fn to_str_mania(&self, soundbank: &mut SoundBank) -> String {
        let keysound = self.get_generic_keysound(soundbank);
        let mut parts = vec![
            self.x.to_string(),
            "192".to_string(),
            self.time.to_string(),
            self.object_type.to_string(),
            self.hit_sound.to_string(),
        ];

        let custom_sample = if keysound.has_custom {
            soundbank.get_sound_sample(keysound.sample.unwrap_or(0))
                .unwrap_or_default()
        } else {
            String::new()
        };

        let volume = if keysound.volume >= 100 { 0 } else { keysound.volume };
        let hit_sample = HitSample {
            normal_set: 0,
            addition_set: 0,
            index: 0,
            volume,
            filename: custom_sample,
        };

        if self.is_hold() {
            if let Some(end_time) = self.end_time() {
                let hit_sample_str = hit_sample.to_str();
                parts.push(format!("{}:{}", end_time, hit_sample_str));
            }
        } else {
            let hit_sample_str = hit_sample.to_str();
            parts.push(hit_sample_str);
        }

        parts.join(",")
    }

    fn to_str_mania_no_soundbank(&self) -> String {
        let mut parts = vec![
            self.x.to_string(),
            "192".to_string(),
            self.time.to_string(),
            self.object_type.to_string(),
            self.hit_sound.to_string(),
        ];

        if self.is_hold() {
            if let Some(end_time) = self.end_time() {
                let hit_sample_str = self.hit_sample.to_str();
                parts.push(format!("{}:{}", end_time, hit_sample_str));
            }
        } else {
            let hit_sample_str = self.hit_sample.to_str();
            parts.push(hit_sample_str);
        }

        parts.join(",")
    }
}

#[derive(Debug, Clone, PartialEq)]
pub struct HitObjects {
    hit_objects: Vec<HitObject>,
}

impl Default for HitObjects {
    fn default() -> Self {
        Self {
            hit_objects: Vec::new(),
        }
    }
}

impl FromStr for HitObjects {
    type Err = String;
    
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Self::from_str_with_mode(s, &OsuMode::Standard)
    }
}

impl HitObjects {
    pub fn from_str_with_mode(s: &str, mode: &OsuMode) -> Result<Self, String> {
        let mut hit_objects = Vec::new();
        
        for line in s.lines() {
            let line = line.trim();
            if line.is_empty() || line.starts_with("//") {
                continue;
            }
            
            let hit_object = HitObject::from_str_with_mode(line, mode)?;
            hit_objects.push(hit_object);
        }
        
        Ok(HitObjects { hit_objects })
    }

    pub fn new() -> Self {
        Self::default()
    }
    
    pub fn add_hit_object(&mut self, hit_object: HitObject) {
        self.hit_objects.push(hit_object);
    }
    
    pub fn count(&self) -> usize {
        self.hit_objects.len()
    }
    
    pub fn hit_circle_count(&self) -> usize {
        self.hit_objects.iter().filter(|obj| obj.is_hit_circle()).count()
    }
    
    pub fn slider_count(&self) -> usize {
        self.hit_objects.iter().filter(|obj| obj.is_slider()).count()
    }

    pub fn spinner_count(&self) -> usize {
        self.hit_objects.iter().filter(|obj| obj.is_spinner()).count()
    }
    
    pub fn start_time(&self) -> Option<f32> {
        self.hit_objects.first().map(|obj| obj.time)
    }
    
    pub fn end_time(&self) -> Option<i32> {
        self.hit_objects.last().and_then(|obj| {
            obj.end_time().or(Some(obj.time as i32))
        })
    }
    
    pub fn length(&self) -> Option<f32> {
        if let (Some(start), Some(end)) = (self.start_time(), self.end_time()) {
            Some(end as f32 - start)
        } else {
            None
        }
    }
    
    pub fn objects_in_time_range(&self, start_time: f32, end_time: f32) -> Vec<&HitObject> {
        self.hit_objects
            .iter()
            .filter(|obj| obj.time >= start_time && obj.time <= (end_time as f32))
            .collect()
    }

    pub fn sort_by_time(&mut self) {
        self.hit_objects.sort_by(|a, b| {
            match (a.time.is_nan(), b.time.is_nan()) {
                (true, true) => std::cmp::Ordering::Equal,
                (true, false) => std::cmp::Ordering::Greater,
                (false, true) => std::cmp::Ordering::Less,
                (false, false) => a.time.partial_cmp(&b.time).unwrap(),
            }
        });
    }
    
    pub fn to_str(&self) -> String {
        self.hit_objects
            .iter()
            .map(|obj| obj.to_str() )
            .collect::<Vec<_>>()
            .join("\n")
    }
}

impl HitObjects {
    pub fn to_str_taiko(&self) -> String {
        self.hit_objects
            .iter()
            .map(|obj| obj.to_str_taiko() )
            .collect::<Vec<_>>()
            .join("\n")
    }

    pub fn to_str_catch(&self) -> String {
        self.hit_objects
            .iter()
            .map(|obj| obj.to_str_catch() )
            .collect::<Vec<_>>()
            .join("\n")
    }

    pub fn to_str_mania(&self, soundbank: &mut SoundBank) -> String {
        self.hit_objects
            .iter()
            .map(|obj| obj.to_str_mania(soundbank) )
            .collect::<Vec<_>>()
            .join("\n")
    }

    pub fn to_str_no_soundbank(&self) -> String {
        self.hit_objects
            .iter()
            .map(|obj| obj.to_str_mania_no_soundbank() )
            .collect::<Vec<_>>()
            .join("\n")
    }

    pub fn to_str_standard(&self) -> String {
        self.to_str()
    }
}

impl<I> Index<I> for HitObjects
where
    I: SliceIndex<[HitObject]>,
{
    type Output = I::Output;

    fn index(&self, index: I) -> &Self::Output {
        &self.hit_objects[index]
    }
}

impl<I> IndexMut<I> for HitObjects
where
    I: SliceIndex<[HitObject], Output = [HitObject]>,
{
    fn index_mut(&mut self, index: I) -> &mut Self::Output {
        &mut self.hit_objects[index]
    }
}

impl IntoIterator for HitObjects {
    type Item = HitObject;
    type IntoIter = std::vec::IntoIter<HitObject>;

    fn into_iter(self) -> Self::IntoIter {
        self.hit_objects.into_iter()
    }
}

impl<'a> IntoIterator for &'a HitObjects {
    type Item = &'a HitObject;
    type IntoIter = std::slice::Iter<'a, HitObject>;

    fn into_iter(self) -> Self::IntoIter {
        self.hit_objects.iter()
    }
}

impl<'a> IntoIterator for &'a mut HitObjects {
    type Item = &'a mut HitObject;
    type IntoIter = std::slice::IterMut<'a, HitObject>;

    fn into_iter(self) -> Self::IntoIter {
        self.hit_objects.iter_mut()
    }
}

impl HitObjects {
    pub fn iter(&'_ self) -> std::slice::Iter<'_, HitObject> {
        self.hit_objects.iter()
    }
    
    pub fn iter_mut(&'_ mut self) -> std::slice::IterMut<'_, HitObject> {
        self.hit_objects.iter_mut()
    }
    
    pub fn get(&self, index: usize) -> Option<&HitObject> {
        self.hit_objects.get(index)
    }
    
    pub fn get_mut(&mut self, index: usize) -> Option<&mut HitObject> {
        self.hit_objects.get_mut(index)
    }
    
    pub fn get_slice<I>(&self, index: I) -> Option<&I::Output>
    where
        I: SliceIndex<[HitObject]>,
    {
        self.hit_objects.get(index)
    }
    
    pub fn get_slice_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
    where
        I: SliceIndex<[HitObject], Output = [HitObject]>,
    {
        self.hit_objects.get_mut(index)
    }
    
    pub fn is_empty(&self) -> bool {
        self.hit_objects.is_empty()
    }
    
    pub fn first(&self) -> Option<&HitObject> {
        self.hit_objects.first()
    }
    
    pub fn last(&self) -> Option<&HitObject> {
        self.hit_objects.last()
    }
    
    pub fn first_mut(&mut self) -> Option<&mut HitObject> {
        self.hit_objects.first_mut()
    }
    
    pub fn last_mut(&mut self) -> Option<&mut HitObject> {
        self.hit_objects.last_mut()
    }
}