-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.cpp
More file actions
89 lines (74 loc) · 1.83 KB
/
Copy pathstorage.cpp
File metadata and controls
89 lines (74 loc) · 1.83 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
#include "storage.h"
#define VOICES_DIRECTORY "/voices"
#define MIDI_DIRECTORY "/midi"
#include <SPI.h>
#include "display.h"
bool SD_storage_available = false;
#ifdef USE_SDFAT
SdFat SD(2);
#endif
void setup_storage () {
#ifndef USE_SDFAT
SPI.setModule (2);
SPI.setClockDivider(SPI_CLOCK_DIV2);
#endif
if (!SD.begin(PB12)) {
display_detail ("SD init fail", ":-(");
delay (1000);
} else {
SD.mkdir (VOICES_DIRECTORY);
SD.mkdir (MIDI_DIRECTORY);
SD_storage_available = true;
}
}
File defaultVoiceFileHandle () {
return openVoiceFile ("");
}
File openVoiceFile (const char* name) {
if (!SD_storage_available) return File();
char buf[32];
strcpy (buf, VOICES_DIRECTORY);
if (name[0] == '\0') { // No name specified: Use first file in dir
File dir = SD.open(buf);
File dummy = dir.openNextFile();
dir.close ();
if (!dummy) return File ();
strcat (buf, "/");
strcat (buf, getFileName (dummy));
dummy.close ();
return SD.open(buf, FILE_WRITE);
} else {
strcat (buf, "/");
strcat (buf, name);
}
return SD.open(buf, FILE_WRITE);
}
File openVoiceDirectory () {
if (!SD_storage_available) return File();
return SD.open(VOICES_DIRECTORY);
}
File defaultMIDIRecHandle () {
return openMidiFile ("");
}
File openMidiDirectory () {
if (!SD_storage_available) return File();
return SD.open(MIDI_DIRECTORY);
}
File openMidiFile (const char* name) {
if (!SD_storage_available) return File();
if (name[0] == '\0') return SD.open (MIDI_DIRECTORY "/0.mid", FILE_WRITE);
char buf[32] = "";
strcat (buf, MIDI_DIRECTORY);
strcat (buf, "/");
strcat (buf, name);
return SD.open(buf, FILE_WRITE);
}
char getname_buf[13];
char *getFileName (File &file) {
#ifdef USE_SDFAT
file.getName (getname_buf, 13);
#else
strcpy (getname_buf, file.name ());
#endif
return getname_buf;
}