Stepdance Software Library
Loading...
Searching...
No Matches
recording.hpp
1#include <stdint.h>
2/*
3Recording Module of the StepDance Control System
4
5This module contains facilities for recording and playback of motion streams.
6
7[More Details to be Added]
8
9A part of the Mixing Metaphors Project
10(c) 2025 Ilan Moyer, Jennifer Jacobs, Devon Frost
11
12*/
13
14#include "core.hpp"
15#include <SD.h>
16#include <string>
17
18#ifndef recording_h //prevent importing twice
19#define recording_h
20
26class RecorderTrack {
27 // a single track used for recording
28 public:
29 RecorderTrack();
30 void begin();
31 int8_t run(); //returns 1 or -1 if step is taken, 0 if not.
32 BlockPort input_target_position;
33
34 private:
35 DecimalPosition target_position = 0;
36 DecimalPosition current_position = 0;
37};
38
46class FourTrackRecorder : public Plugin{
47 // Simultaneously records four motion streams to an SD card file.
48
49 public:
50 FourTrackRecorder();
54 void begin();
60 void start(const char *recording_name, uint8_t recording_length_min = 30); // start recording
64 void pause(); // pause recording
68 void resume(); //continues recording
72 void stop(); // stop recording
78 void set_resolution(float input_units, float per_steps = 1.0);
82 void enroll(RPC *rpc, const String& instance_name);
83
84
85 static const uint8_t NUM_CHANNELS = 4;
86 RecorderTrack recorder_tracks[NUM_CHANNELS];
91 BlockPort& input_1 = recorder_tracks[0].input_target_position;
95 BlockPort& input_2 = recorder_tracks[1].input_target_position;
99 BlockPort& input_3 = recorder_tracks[2].input_target_position;
103 BlockPort& input_4 = recorder_tracks[3].input_target_position;
107 volatile long current_sample_index = 0;
115 volatile bool recorder_active = false;
116
117 private:
118 float32_t resolution_units_per_step = STANDARD_RATIO_MM;
119 volatile bool in_recording = false; //true when paused
120 char recording_filename[30];
121 char length_filename[30];
122 FsFile active_recording_file;
123
124 protected:
125 void run();
126};
127
135class FourTrackPlayer : public Plugin{
136
137 public:
138 FourTrackPlayer();
142 void begin();
147 void start(const char *recording_name = "recording");
151 void pause();
155 void resume();
159 void stop();
165 void set_resolution(float output_units, float per_steps = 1.0);
169 void enroll(RPC *rpc, const String& instance_name);
170
171 //BlockPorts
172 static const uint8_t NUM_CHANNELS = 4;
173 BlockPort output_BlockPorts[NUM_CHANNELS];
178 BlockPort& output_1 = output_BlockPorts[0];
182 BlockPort& output_2 = output_BlockPorts[1];
186 BlockPort& output_3 = output_BlockPorts[2];
190 BlockPort& output_4 = output_BlockPorts[3];
194 volatile long current_sample_index = 0;
202 volatile bool playback_active = false;
203
204 private:
205 // BlockPort output positions
206 DecimalPosition output_positions[NUM_CHANNELS];
207 float32_t resolution_units_per_step = STANDARD_RATIO_MM;
208 volatile bool in_playback = false; //true when paused
209 char recording_filename[30];
210 char length_filename[30];
211 FsFile active_playback_file;
212
213 protected:
214 void run();
215};
216
217// --- SD CARD UTILITIES ---
218void initialize_sd_card();
219
220#endif //recording_h
BlockPorts provide a unified interface for mapping inputs and outputs of different StepDance componen...
Definition core.hpp:148
void set_resolution(float output_units, float per_steps=1.0)
Sets the resolution for playback in world units per step.
BlockPort & output_2
Output BlockPort for the second playback channel. Map downstream components to this port.
Definition recording.hpp:182
void start(const char *recording_name="recording")
Starts playback of a recording with the specified name.
void stop()
Stops the current playback.
void pause()
Pauses the current playback.
void begin()
Initializes the FourTrackPlayer. Must be called before using the player.
volatile long current_sample_index
Current sample index in the playback.
Definition recording.hpp:194
void resume()
Resumes a paused playback.
long max_num_playback_samples
Maximum number of samples in the playback.
Definition recording.hpp:198
BlockPort & output_3
Output BlockPort for the third playback channel. Map downstream components to this port.
Definition recording.hpp:186
BlockPort & output_1
Output BlockPort for the first playback channel. Map downstream components to this port.
Definition recording.hpp:178
BlockPort & output_4
Output BlockPort for the fourth playback channel. Map downstream components to this port.
Definition recording.hpp:190
volatile bool playback_active
Indicates whether the player is currently active.
Definition recording.hpp:202
void stop()
Stops the current recording.
BlockPort & input_1
Input BlockPort for the first recording channel. Map upstream components to this port.
Definition recording.hpp:91
volatile long current_sample_index
Current sample index in the recording.
Definition recording.hpp:107
BlockPort & input_4
Input BlockPort for the fourth recording channel. Map upstream components to this port.
Definition recording.hpp:103
void resume()
Resumes a paused recording.
void start(const char *recording_name, uint8_t recording_length_min=30)
Starts a new recording with the specified name and optional length.
volatile bool recorder_active
Indicates whether the recorder is currently active.
Definition recording.hpp:115
void pause()
Pauses the current recording.
void begin()
Initializes the FourTrackRecorder. Must be called before using the recorder.
long max_num_samples
Maximum number of samples in the recording.
Definition recording.hpp:111
BlockPort & input_3
Input BlockPort for the third recording channel. Map upstream components to this port.
Definition recording.hpp:99
BlockPort & input_2
Input BlockPort for the second recording channel. Map upstream components to this port.
Definition recording.hpp:95
void set_resolution(float input_units, float per_steps=1.0)
Sets the resolution for recording in world units per step.
RPC class for handling remote procedure calls over serial streams.
Definition rpc.hpp:35
RecorderTrack handles recording of a single motion stream.
Definition recording.hpp:26