zynaddsubfx

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

MiddleWare.h (3683B)


      1 /*
      2   ZynAddSubFX - a software synthesizer
      3 
      4   MiddleWare.h - RT & Non-RT Glue Layer
      5   Copyright (C) 2016 Mark McCurry
      6 
      7   This program is free software; you can redistribute it and/or
      8   modify it under the terms of the GNU General Public License
      9   as published by the Free Software Foundation; either version 2
     10   of the License, or (at your option) any later version.
     11 */
     12 #pragma once
     13 #include <functional>
     14 #include <cstdarg>
     15 #include <string>
     16 
     17 class Fl_Osc_Interface;
     18 
     19 namespace rtosc {
     20     struct MergePorts;
     21 }
     22 
     23 namespace zyn {
     24 
     25 struct SYNTH_T;
     26 class  Master;
     27 class PresetsStore;
     28 
     29 //Link between realtime and non-realtime layers
     30 class MiddleWare
     31 {
     32     public:
     33         MiddleWare(SYNTH_T synth, class Config *config,
     34                    int preferred_port = -1);
     35         ~MiddleWare(void);
     36         void updateResources(Master *m);
     37         //returns internal master pointer
     38         class Master *spawnMaster(void);
     39 
     40         //Enable AutoSave Functionality
     41         void enableAutoSave(int interval_sec=60);
     42 
     43         //Check for old automatic saves which should only exist if multiple
     44         //instances are in use OR when there was a crash
     45         //
     46         //When an old save is found return the id of the save file
     47         int checkAutoSave(void) const;
     48 
     49         void removeAutoSave(void);
     50 
     51         //return  UI interface
     52         Fl_Osc_Interface *spawnUiApi(void);
     53         //Set callback to push UI events to
     54         void setUiCallback(std::size_t gui_id, void(*cb)(void*,const char *),void *ui);
     55         //Set callback to run while busy
     56         void setIdleCallback(void(*cb)(void*),void *ptr);
     57         //Handle events
     58         void tick(void);
     59         //Do A Readonly Operation (For Parameter Copy)
     60         void doReadOnlyOp(std::function<void()>);
     61         //Handle a rtosc Message uToB
     62         void transmitMsg(const char *);
     63         //Handle a rtosc Message uToB
     64         void transmitMsg(const char *, const char *args, ...);
     65         //Handle a rtosc Message uToB
     66         void transmitMsg_va(const char *, const char *args, va_list va);
     67 
     68         //Handle a rtosc Message uToB, if sender is GUI
     69         void transmitMsgGui(std::size_t gui_id, const char * msg);
     70         //Handle a rtosc Message uToB, if sender is GUI
     71         void transmitMsgGui(std::size_t gui_id, const char *, const char *args, ...);
     72         //Handle a rtosc Message uToB, if sender is GUI
     73         void transmitMsgGui_va(std::size_t gui_id, const char *, const char *args, va_list va);
     74 
     75         //Send a message to middleware from an arbitrary thread
     76         void messageAnywhere(const char *msg, const char *args, ...);
     77 
     78         //Indicate that a bank will be loaded
     79         //NOTE: Can only be called by realtime thread
     80         void pendingSetBank(int bank);
     81 
     82         //Indicate that a program will be loaded on a known part
     83         //NOTE: Can only be called by realtime thread
     84         void pendingSetProgram(int part, int program);
     85 
     86         std::string getProgramName(int program) const;
     87 
     88         //Get/Set the active bToU url
     89         std::string activeUrl(void) const;
     90         void activeUrl(std::string u);
     91         //View Synthesis Parameters
     92         const SYNTH_T &getSynth(void) const;
     93         //liblo stuff
     94         char* getServerAddress(void) const;
     95         char* getServerPort(void) const;
     96 
     97         const PresetsStore& getPresetsStore() const;
     98         PresetsStore& getPresetsStore();
     99 
    100         //!Make @p new_master the current master
    101         //!@warning use with care, and only in frozen state
    102         void switchMaster(Master* new_master);
    103 
    104         void discardAllbToUButHandleFree();
    105 
    106         static const rtosc::MergePorts& getAllPorts();
    107 
    108     private:
    109         class MiddleWareImpl *impl;
    110 };
    111 
    112 }
    113