Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
browser.h
1/*
2 * Copyright © 2019-2023 Synthstrom Audible Limited
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include "definitions_cxx.hpp"
21#include "gui/ui/qwerty_ui.h"
22#include "hid/button.h"
23#include "io/debug/log.h"
24#include "model/favourite/favourite_manager.h"
25#include "storage/file_item.h"
26#include "util/container/array/c_string_array.h"
27
28extern "C" {
29#include "fatfs/ff.h"
30
31FRESULT f_readdir_get_filepointer(DIR* dp, /* Pointer to the open directory object */
32 FILINFO* fno, /* Pointer to file information to return */
33 FilePointer* filePointer);
34}
35
36class Instrument;
37class FileItem;
39class Song;
40
41// FIXME: std::expected<std::pair<bool, FileItem*>, Error>
43 FileItem* fileItem;
44 bool loadedFromFile;
45 Error error;
46};
47
48struct Slot {
49 int16_t slot;
50 int8_t subSlot;
51};
52
53#define NUM_FILES_ON_SCREEN 3
54
55#define CATALOG_SEARCH_LEFT 0
56#define CATALOG_SEARCH_RIGHT 1
57#define CATALOG_SEARCH_BOTH 2
58
59#define FILE_ITEMS_MAX_NUM_ELEMENTS 20
60#define FILE_ITEMS_MAX_NUM_ELEMENTS_FOR_NAVIGATION 20 // It "should" be able to be way less than this.
61
62extern char const* allowedFileExtensionsXML[];
63
64class Browser : public QwertyUI {
65public:
66 Browser();
67
68 void close();
69 virtual Error getCurrentFilePath(String* path) = 0;
70 ActionResult buttonAction(deluge::hid::Button b, bool on, bool inCardRoutine) override;
71 ActionResult padAction(int32_t x, int32_t y, int32_t velocity) override;
72 ActionResult verticalEncoderAction(int32_t offset, bool inCardRoutine) override;
73 void currentFileDeleted();
74 Error goIntoFolder(char const* folderName);
75 Error createFolder();
76 Error createFoldersRecursiveIfNotExists(const char* path);
77 void selectEncoderAction(int8_t offset) override;
78 static FileItem* getCurrentFileItem();
79 Error readFileItemsForFolder(char const* filePrefixHere, bool allowFolders, char const** allowedFileExtensionsHere,
80 char const* filenameToStartAt, int32_t newMaxNumFileItems,
81 int32_t newCatalogSearchDirection = CATALOG_SEARCH_BOTH);
82 Error setFileByFullPath(OutputType outputType, char const* fullPath);
83 void sortFileItems();
84 FileItem* getNewFileItem();
85 static void emptyFileItems();
86 static void deleteSomeFileItems(int32_t startAt, int32_t stopAt);
87 static void deleteFolderAndDuplicateItems(Availability instrumentAvailabilityRequirement = Availability::ANY);
88 Error getUnusedSlot(OutputType outputType, String* newName, char const* thingName);
89 bool opened() override;
90 void cullSomeFileItems();
91 bool checkFP();
92
93 void renderOLED(deluge::hid::display::oled_canvas::Canvas& canvas) override;
94
95 static String currentDir;
96 static CStringArray fileItems;
97 static int32_t numFileItemsDeletedAtStart;
98 static int32_t numFileItemsDeletedAtEnd;
99 static char const* firstFileItemRemaining;
100 static char const* lastFileItemRemaining;
101
102 static OutputType outputTypeToLoad;
103 static char const* filenameToStartSearchAt;
104
105 // ui
106 bool exitUI() override {
107 Browser::close();
108 return true;
109 }
110
111protected:
112 Error setEnteredTextFromCurrentFilename();
113 Error goUpOneDirectoryLevel();
114 virtual Error arrivedInNewFolder(int32_t direction, char const* filenameToStartAt = nullptr,
115 char const* defaultDir = nullptr);
116 bool predictExtendedText() override;
117 void goIntoDeleteFileContextMenu();
118 ActionResult mainButtonAction(bool on);
119 virtual void exitAction();
120 virtual ActionResult backButtonAction();
121 virtual void folderContentsReady(int32_t entryDirection) {}
122 virtual void currentFileChanged(int32_t movementDirection) {}
123 void displayText(bool blinkImmediately = false) override;
124 static Slot getSlot(char const* displayName);
125 Error readFileItemsFromFolderAndMemory(Song* song, OutputType outputType, char const* filePrefixHere,
126 char const* filenameToStartAt, char const* defaultDirToAlsoTry,
127 bool allowFoldersint,
128 Availability availabilityRequirement = Availability::ANY,
129 int32_t newCatalogSearchDirection = CATALOG_SEARCH_RIGHT);
130 void favouritesChanged();
131
132 static int32_t fileIndexSelected; // If -1, we have not selected any real file/folder. Maybe there are no files, or
133 // maybe we're typing a new name.
134 static int32_t scrollPosVertical;
135 static int32_t
136 numCharsInPrefix; // Only used for deciding Drum names within Kit. Oh and initial text scroll position.
137 static bool qwertyVisible;
138 static bool arrivedAtFileByTyping;
139 static bool allowFoldersSharingNameWithFile;
140 static char const** allowedFileExtensions;
141
142 const uint8_t* fileIcon;
143 const uint8_t* fileIconPt2;
144 int32_t fileIconPt2Width;
145
146 // 7Seg Only
147 static int8_t numberEditPos; // -1 is default
148 static NumericLayerScrollingText* scrollingText;
149 bool shouldWrapFolderContents; // As in, wrap around at the end.
150
151 bool mayDefaultToBrandNewNameOnEntry;
152 bool qwertyAlwaysVisible;
153 // filePrefix is SONG/SYNT/SAMP etc., signifying the portion of the filesystem you're in
154 char const* filePrefix;
155 bool shouldInterpretNoteNamesForThisBrowser;
156};
157
158inline void printInstrumentFileList(const char* where) {
159 D_PRINT("\n");
160 D_PRINT(where);
161 D_PRINT(" List: \n");
162 for (uint32_t idx = 0; idx < Browser::fileItems.getNumElements(); ++idx) {
163 FileItem* fileItem = (FileItem*)Browser::fileItems.getElementAddress(idx);
164 D_PRINTLN(" - %s (%lu)", fileItem->displayName, fileItem->filePointer.sclust);
165 }
166 D_PRINT("\n");
167}
bool exitUI() override
returns whether a UI exited
Definition browser.h:106
Definition c_string_array.h:23
Definition file_item.h:24
Definition instrument.h:45
Definition numeric_layer_scrolling_text.h:22
Definition song.h:104
Definition d_string.h:46
Definition browser.h:42
Definition browser.h:48