1 /*
2   ZynAddSubFX - a software synthesizer
3 
4   Bank.h - Instrument Bank
5   Copyright (C) 2002-2005 Nasca Octavian Paul
6   Author: Nasca Octavian Paul
7 
8   This program is free software; you can redistribute it and/or
9   modify it under the terms of the GNU General Public License
10   as published by the Free Software Foundation; either version 2
11   of the License, or (at your option) any later version.
12 */
13 
14 #ifndef BANK_H
15 #define BANK_H
16 
17 #include <string>
18 #include <vector>
19 #include "../globals.h"
20 #include "Config.h"
21 
22 //entries in a bank
23 #define BANK_SIZE 160
24 
25 namespace zyn {
26 
27 /**The instrument Bank*/
28 class Bank
29 {
30     public:
31         /**Constructor*/
32         Bank(Config* config);
33         ~Bank();
34         std::string getname(unsigned int ninstrument);
35         std::string getnamenumbered(unsigned int ninstrument);
36         //if newslot==-1 then this is ignored, else it will be put on that slot
37         int setname(unsigned int ninstrument,
38                      const std::string &newname,
39                      int newslot);
40 
41         /**returns true when slot is empty*/
42         bool emptyslot(unsigned int ninstrument);
43 
44         /**Empties out the selected slot*/
45         int clearslot(unsigned int ninstrument);
46         /**Saves the given Part to slot*/
47         int savetoslot(unsigned int ninstrument, class Part * part);
48         /**Loads the given slot into a Part*/
49         int loadfromslot(unsigned int ninstrument, class Part * part);
50 
51         /**Swaps Slots*/
52         int swapslot(unsigned int n1, unsigned int n2);
53 
54         int loadbank(std::string bankdirname) NONREALTIME;
55         int newbank(std::string newbankdirname) NONREALTIME;
56 
57         std::string bankfiletitle; //this is shown on the UI of the bank (the title of the window)
58         int locked();
59 
60         void rescanforbanks();
61 
62         void setMsb(uint8_t msb);
63         void setLsb(uint8_t lsb);
64 
65         struct bankstruct {
66             bool operator<(const bankstruct &b) const;
67             std::string dir;
68             std::string name;
69         };
70 
71         std::vector<bankstruct> banks;
72         int bankpos;
73 
74         struct ins_t {
75             ins_t(void);
76             std::string name;
77             //All valid instruments must have a non-empty filename
78             std::string filename;
79         } ins[BANK_SIZE];
80 
81         std::vector<std::string> search(std::string) const;
82         std::vector<std::string> blist(std::string);
83 
84     private:
85 
86         //it adds a filename to the bank
87         //if pos is -1 it try to find a position
88         //returns -1 if the bank is full, or 0 if the instrument was added
89         int addtobank(int pos, std::string filename, std::string name);
90 
91         void deletefrombank(int pos);
92 
93         void clearbank();
94 
95         std::string defaultinsname;
96         std::string dirname;
97 
98         void scanrootdir(std::string rootdir); //scans a root dir for banks
99 
100         /** Expends ~ prefix in dirname, if any */
101         void expanddirname(std::string &dirname);
102 
103         /** Ensure that the directory name is suffixed by a
104          * directory separator */
105         void normalizedirsuffix(std::string &dirname) const;
106 
107         Config* const config;
108         class BankDb *db;
109 
110     public:
111         uint8_t bank_msb;
112         uint8_t bank_lsb;
113 };
114 
115 }
116 
117 #endif
118