Data Classes
The RCT API provides multiple data classes to represent various elements of a chart.
Class List
- BPM Class - BPM change points
- Beat Class - Beat to time conversion
- Speed Class - Speed change points
- Note Class - Notes
BPM Class
Represents a BPM change point.
Constructor
from rct_api import BPM
bpm = BPM(time=0, bpm=120.0)
Properties
| Property | Type | Description |
|---|---|---|
time | float | Time (milliseconds) |
bpm | float | BPM value |
Example
from rct_api import get_current_chart
chart = get_current_chart()
if chart and chart.bpm:
print("=== BPM Information ===")
for bpm in chart.bpm:
print(f"Time: {bpm.time}ms, BPM: {bpm.bpm}")
Beat Class
Used to convert between beats and time, supports variable BPM.
Constructor
Method 1: Create from BPM List
from rct_api import Beat
bpm_list = [[0, 120], [4000, 140], [8000, 130]]
beat = Beat(bpm_list)
Parameters:
bpm_list: BPM list in format[[time(ms), bpm], ...]
Method 2: Create from BPM Objects (Recommended)
from rct_api import Beat, get_current_chart
chart = get_current_chart()
beat = Beat.from_bpm_objects(chart.bpm)
RECOMMENDED
When working with chart data, it's recommended to use the Beat.from_bpm_objects() method, which can directly use the chart.bpm object list for cleaner code.
Methods
get_time()
Get time from beat number (beat → ms).
Syntax
time = beat.get_time(beat_number)
Parameters
| Parameter | Type | Description |
|---|---|---|
beat_number | float | Beat number |
Return Value
Corresponding time (milliseconds)
Example
from rct_api import Beat, get_current_chart
chart = get_current_chart()
beat = Beat.from_bpm_objects(chart.bpm)
# Get time of beat 4
time = beat.get_time(4.0)
print(f"Time of beat 4: {time}ms")
# Get time of beat 8.5
time = beat.get_time(8.5)
print(f"Time of beat 8.5: {time}ms")
get_beat()
Get beat number from time (ms → beat).
Syntax
beats = beat.get_beat(time)
Parameters
| Parameter | Type | Description |
|---|---|---|
time | float | Time (milliseconds) |
Return Value
Corresponding beat number (float)
Example
from rct_api import Beat, get_current_chart
chart = get_current_chart()
beat = Beat.from_bpm_objects(chart.bpm)
# Get beat number at 5000ms
beats = beat.get_beat(5000)
print(f"Beat number at 5000ms: {beats:.3f}")
from_bpm_objects()
Class method: Create Beat instance from BPM object list.
Syntax
beat = Beat.from_bpm_objects(bpm_objects)
Parameters
| Parameter | Type | Description |
|---|---|---|
bpm_objects | List[BPM] | BPM object list |
Return Value
Beat instance
Example
from rct_api import Beat, get_current_chart
chart = get_current_chart()
beat = Beat.from_bpm_objects(chart.bpm)
Complete Example
# Description: Generate notes by beat
from rct_api import get_current_chart, save_current_chart, Beat, Note
def main():
chart = get_current_chart()
if not chart or not chart.bpm:
print("Error: Unable to get chart or BPM information")
return
# Create Beat converter
beat = Beat.from_bpm_objects(chart.bpm)
# Generate a Tap note every half beat from beat 1-8
for i in range(16): # 8 beats × 2 notes per beat
beat_number = 1.0 + i * 0.5
time = beat.get_time(beat_number)
degree = (i * 45) % 360
chart.add_note(Note.TAP, time, degree)
print(f"Beat {beat_number:.1f} -> {time:.0f}ms")
chart.sort()
save_current_chart(chart)
print("Generation complete")
if __name__ == "__main__":
main()
Speed Class
Represents a Speed change point.
Constructor
from rct_api import Speed
speed = Speed(time=1000, speed=2.0, smooth=0)
Properties
| Property | Type | Description |
|---|---|---|
time | float | Time (milliseconds) |
speed | float | Speed multiplier |
smooth | int | Smooth type (0=none, 1=smooth) |
Example
from rct_api import get_current_chart
chart = get_current_chart()
if chart and chart.speed:
print("=== Speed Information ===")
for speed in chart.speed:
smooth_str = "Smooth" if speed.smooth == 1 else "None"
print(f"Time: {speed.time}ms, Multiplier: {speed.speed}x, Smooth: {smooth_str}")
Note Class
Represents a note.
Constructor
from rct_api import Note
note = Note(type, time, degree, *extra)
Note Type Constants
Note.TAP = 0 # Tap
Note.FLICK = 1 # Flick
Note.SLIDE = 2 # Slide
Note.ROTATE = 4 # Rotate
Note.CATCH = 5 # Catch
Note.BOMB = 6 # Bomb
Note.TRAIL = 11 # Trail
Note Structure
Different types of notes have different parameter structures:
Tap Note
Note(Note.TAP, time, degree)
Example:
tap = Note(Note.TAP, 1000, 45)
Flick Note
Note(Note.FLICK, time, degree)
Example:
flick = Note(Note.FLICK, 2000, 90)
Catch Note
Note(Note.CATCH, time, degree)
Example:
catch = Note(Note.CATCH, 3000, 180)
Bomb Note
Note(Note.BOMB, time, degree)
Example:
bomb = Note(Note.BOMB, 4000, 270)
Trail Note
Note(Note.TRAIL, time, degree, delta, prev_curv, next_curv)
Parameters:
time: Time (milliseconds)degree: Starting angledelta: Angle changeprev_curv: Previous curvaturenext_curv: Next curvature
Example:
trail = Note(Note.TRAIL, 5000, 0, 180, 0, 0)
Rotate Note
Note(Note.ROTATE, time, degree, delta, prev_curv, next_curv)
Parameters:
time: Time (milliseconds)degree: Starting angledelta: Angle changeprev_curv: Previous curvaturenext_curv: Next curvature
Example:
rotate = Note(Note.ROTATE, 6000, 0, 360, 0, 0)
Slide Note
Note(Note.SLIDE, time, degree, slidetype, end_degree, snap, amount, prev_curv, next_curv)
Parameters:
time: Time (milliseconds)degree: Starting angleslidetype: Slide typeend_degree: Ending anglesnap: Snap parameteramount: Amount parameterprev_curv: Previous curvaturenext_curv: Next curvature
Example:
slide = Note(Note.SLIDE, 7000, 0, 1, 180, 4, 8, 0, 0)
Accessing Note Properties
from rct_api import get_current_chart, Note
chart = get_current_chart()
if chart and chart.notes:
for note in chart.notes[:5]: # First 5 notes
print(f"Type: {note.type}")
print(f"Time: {note.time}ms")
print(f"Angle: {note.degree}°")
# Check by type
if note.type == Note.TAP:
print(" -> Tap Note")
elif note.type == Note.TRAIL:
print(f" -> Trail Note (ending angle: {note.data[0]}°)")
print()
Complete Example: Using All Data Classes
# Description: Comprehensive data classes example
from rct_api import get_current_chart, Beat, Note
def main():
chart = get_current_chart()
if not chart:
print("Error: Unable to get chart")
return
# BPM Information
print("=== BPM Information ===")
for bpm in chart.bpm:
print(f"{bpm.time}ms: {bpm.bpm} BPM")
print()
# Speed Information
print("=== Speed Information ===")
for speed in chart.speed:
print(f"{speed.time}ms: {speed.speed}x (smooth: {speed.smooth})")
print()
# Analyze notes using Beat class
print("=== Note Beat Analysis ===")
beat = Beat.from_bpm_objects(chart.bpm)
type_names = {
Note.TAP: "Tap",
Note.FLICK: "Flick",
Note.SLIDE: "Slide",
Note.ROTATE: "Rotate",
Note.CATCH: "Catch",
Note.BOMB: "Bomb",
Note.TRAIL: "Trail"
}
for i, note in enumerate(chart.notes[:10]):
note_beat = beat.get_beat(note.time)
type_name = type_names.get(note.type, f"Unknown({note.type})")
print(f"{i+1}. {type_name} - {note.time:.0f}ms (beat {note_beat:.2f}) - {note.degree}°")
if __name__ == "__main__":
main()