zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

Bank.h (3016B)


      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 #include <stdint.h>
     22 
     23 //entries in a bank
     24 #define BANK_SIZE 160
     25 
     26 namespace zyn {
     27 
     28 /**The instrument Bank*/
     29 class Bank
     30 {
     31     public:
     32         /**Constructor*/
     33         Bank(Config* config);
     34         ~Bank();
     35         std::string getname(unsigned int ninstrument);
     36         std::string getnamenumbered(unsigned int ninstrument);
     37         //if newslot==-1 then this is ignored, else it will be put on that slot
     38         int setname(unsigned int ninstrument,
     39                      const std::string &newname,
     40                      int newslot);
     41 
     42         /**returns true when slot is empty*/
     43         bool emptyslot(unsigned int ninstrument);
     44 
     45         /**Empties out the selected slot*/
     46         int clearslot(unsigned int ninstrument);
     47         /**Saves the given Part to slot*/
     48         int savetoslot(unsigned int ninstrument, class Part * part);
     49         /**Loads the given slot into a Part*/
     50         int loadfromslot(unsigned int ninstrument, class Part * part);
     51 
     52         /**Swaps Slots*/
     53         int swapslot(unsigned int n1, unsigned int n2);
     54 
     55         int loadbank(std::string bankdirname) NONREALTIME;
     56         int newbank(std::string newbankdirname) NONREALTIME;
     57 
     58         std::string bankfiletitle; //this is shown on the UI of the bank (the title of the window)
     59         int locked();
     60 
     61         void rescanforbanks();
     62 
     63         void setMsb(uint8_t msb);
     64         void setLsb(uint8_t lsb);
     65 
     66         struct bankstruct {
     67             bool operator<(const bankstruct &b) const;
     68             std::string dir;
     69             std::string name;
     70         };
     71 
     72         std::vector<bankstruct> banks;
     73         int bankpos;
     74 
     75         struct ins_t {
     76             ins_t(void);
     77             std::string name;
     78             //All valid instruments must have a non-empty filename
     79             std::string filename;
     80         } ins[BANK_SIZE];
     81 
     82         std::vector<std::string> search(std::string) const;
     83         std::vector<std::string> blist(std::string);
     84 
     85     private:
     86 
     87         //it adds a filename to the bank
     88         //if pos is -1 it try to find a position
     89         //returns -1 if the bank is full, or 0 if the instrument was added
     90         int addtobank(int pos, std::string filename, std::string name);
     91 
     92         void deletefrombank(int pos);
     93 
     94         void clearbank();
     95 
     96         std::string defaultinsname;
     97         std::string dirname;
     98 
     99         void scanrootdir(std::string rootdir); //scans a root dir for banks
    100 
    101         Config* const config;
    102         class BankDb *db;
    103 
    104     public:
    105         uint8_t bank_msb;
    106         uint8_t bank_lsb;
    107 };
    108 
    109 }
    110 
    111 #endif