-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecord.cpp
More file actions
124 lines (111 loc) · 3.06 KB
/
record.cpp
File metadata and controls
124 lines (111 loc) · 3.06 KB
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
/*
plexus - a launchpad cv/gate sequencer/keyboard/arpeggiator
Copyright (C) 2017 Dougall IRVING
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "led.h"
#include "playback.h"
#include "hardware.h"
#include "notes.h"
#include "record.h"
// current output state of record
byte record_led = 0;
boolean record_led_on = false;
typedef struct Record
{
boolean recording;
byte initial_button;
byte current_step;
Sequence * sequence;
}
Record;
Record record;
byte temp_seq[SEQUENCE_LENGTH];
void record_setup()
{
record.current_step = 0;
record.recording = false;
record.initial_button = 0;
record_led = 0;
record_led_on = false;
}
void record_start( const byte voice )
{
record.current_step = 0;
record.recording = true;
record.sequence = playback[voice].sequence;
record_led = 0;
record_led_on = false;
grid_led_update = true;
}
void record_button_down ( const byte button)
{
if (record.recording)
{
byte step = record.current_step;
record.sequence->steps[step].gate = true;
record.sequence->steps[step].gate_length = 1;
if (step == 0)
{
record.initial_button = button;
record.sequence->steps[0].offset_x = 0;
record.sequence->steps[0].offset_y = 0;
}
else
{
unsigned char x = get_x_from_button(button);
unsigned char y = get_y_from_button(button);
unsigned char start_x = get_x_from_button(record.initial_button);
unsigned char start_y = get_y_from_button(record.initial_button);
record.sequence->steps[step].offset_x = (x - start_x);
record.sequence->steps[step].offset_y = (y - start_y);
}
record.current_step++;
record.sequence->length = record.current_step;
if (record.current_step == SEQUENCE_LENGTH)
{
record.recording = false;
}
record_led = button;
record_led_on = true;
grid_led_update = true;
}
}
boolean record_led_update()
{
//the last entered value is red.
//yellow horixontal bar graph at bottom showing sequence length
for (int idx = 0; idx < GRID_SIZE; idx++ )
{
if (( idx == record_led ) && (record_led_on))
{
if (set_grid_led(idx, LED_RED))
return true;
}
else if ((record.initial_button == idx)&& (record_led_on))
{
if (set_grid_led(idx, LED_GREEN))
return true;
}
else if ((idx > 55) && (idx <= 55 + record.current_step))
{
if (set_grid_led(idx, LED_YELLOW))
return true;
}
else
{
if (set_grid_led(idx, LED_OFF))
return true;
}
}
return false;
}