zynaddsubfx

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

commit cac44090604c8582f8484ab999c7a8f70cc45c31
parent 3a87861339379f7129cf2e0c654c4855c6cc7e6d
Author: fundamental <mark.d.mccurry@gmail.com>
Date:   Sun,  2 May 2010 11:32:21 -0400

Reducing lock time for instrument load

Diffstat:
Msrc/Misc/Bank.cpp | 19++++++++++++++-----
Msrc/Misc/Bank.h | 2+-
Msrc/Misc/Part.cpp | 6+++++-
Msrc/Misc/Part.h | 3+++
Msrc/Params/LFOParams.cpp | 3+--
Msrc/UI/BankUI.fl | 17+++++++----------
6 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/src/Misc/Bank.cpp b/src/Misc/Bank.cpp @@ -26,7 +26,9 @@ #include <stdlib.h> #include <dirent.h> #include <sys/stat.h> +#include <algorithm> +#include <pthread.h> #include <sys/types.h> #include <fcntl.h> #include <unistd.h> @@ -34,6 +36,8 @@ #include "Config.h" +using namespace std; + #define INSTRUMENT_EXTENSION ".xiz" //if this file exists into a directory, this make the directory to be considered as a bank, even if it not contains a instrument file @@ -237,16 +241,21 @@ void Bank::savetoslot(unsigned int ninstrument, Part *part) /* * Loads the instrument from the bank */ -void Bank::loadfromslot(unsigned int ninstrument, Part *part) +void Bank::loadfromslot(unsigned int ninstrument, Part *&part) { if(emptyslot(ninstrument)) return; - part->defaultsinstrument(); - -// printf("load: %s\n",ins[ninstrument].filename); + Part *p = new Part(part->getMicrotonal(), part->getFFT(), part->mutex); + p->loadXMLinstrument(ins[ninstrument].filename); + p->Penabled = true; + p->applyparameters(); - part->loadXMLinstrument(ins[ninstrument].filename); + //swap pointers to greatly reduce locked time + pthread_mutex_lock(part->mutex); + swap(part,p); + delete p; + pthread_mutex_unlock(part->mutex); } diff --git a/src/Misc/Bank.h b/src/Misc/Bank.h @@ -57,7 +57,7 @@ class Bank /**Saves the given Part to slot*/ void savetoslot(unsigned int ninstrument, Part *part); /**Loads the given slot into a Part*/ - void loadfromslot(unsigned int ninstrument, Part *part); + void loadfromslot(unsigned int ninstrument, Part *&part); /**Swaps Slots*/ void swapslot(unsigned int n1, unsigned int n2); diff --git a/src/Misc/Part.cpp b/src/Misc/Part.cpp @@ -178,7 +178,11 @@ void Part::cleanup() Part::~Part() { - cleanup(); + for(int k = 0; k < POLIPHONY; k++) + KillNotePos(k); + for(int nefx = 0; nefx < NUM_PART_EFX; nefx++) + partefx[nefx]->cleanup(); + for(int n = 0; n < NUM_KIT_ITEMS; n++) { if(kit[n].adpars != NULL) delete (kit[n].adpars); diff --git a/src/Misc/Part.h b/src/Misc/Part.h @@ -106,6 +106,9 @@ class Part void setkeylimit(unsigned char Pkeylimit); void setkititemstatus(int kititem, int Penabled_); + Microtonal *getMicrotonal(){return microtonal;}; + FFTwrapper *getFFT(){return fft;}; + unsigned char Penabled; /**<if the part is enabled*/ unsigned char Pvolume; /**<part volume*/ unsigned char Pminkey; /**<the minimum key that the part receives noteon messages*/ diff --git a/src/Params/LFOParams.cpp b/src/Params/LFOParams.cpp @@ -25,7 +25,7 @@ #include "../globals.h" #include "LFOParams.h" -int LFOParams::time; +int LFOParams::time=0; LFOParams::LFOParams(char Pfreq_, char Pintensity_, @@ -55,7 +55,6 @@ LFOParams::LFOParams(char Pfreq_, Ddelay = Pdelay_; Dcontinous = Pcontinous_; fel = fel_; - time = 0; defaults(); } diff --git a/src/UI/BankUI.fl b/src/UI/BankUI.fl @@ -1,5 +1,5 @@ # data file for the Fltk User Interface Designer (fluid) -version 1.0107 +version 1.0300 header_name {.h} code_name {.cc} decl {//Copyright (c) 2002-2005 Nasca Octavian Paul} {} @@ -31,13 +31,13 @@ decl {\#include "../Misc/Config.h"} {public } class BankProcess_ {} { - Function {process()} {open return_type {virtual void} + Function {process()} {return_type {virtual void} } {} decl {Bank *bank;} {public } } -class BankSlot {open : {public Fl_Button,BankProcess_} +class BankSlot {: {public Fl_Button,BankProcess_} } { Function {BankSlot(int x,int y, int w, int h, const char *label=0):Fl_Button(x,y,w,h,label)} {} { code {what=NULL; @@ -59,8 +59,7 @@ int tmp=Fl_Button::handle(event); if ((*what!=0) && Fl::event_inside(this)) (bp->*fnc)(); return(tmp);} {} } - Function {init(int nslot_, int *what_, int *whatslot_,void (BankProcess_:: *fnc_)(void),BankProcess_ *bp_,Bank *bank_,int *nselected_)} {open - } { + Function {init(int nslot_, int *what_, int *whatslot_,void (BankProcess_:: *fnc_)(void),BankProcess_ *bp_,Bank *bank_,int *nselected_)} {} { code {nslot=nslot_; what=what_; whatslot=whatslot_; @@ -74,8 +73,7 @@ labelsize(13); align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_CLIP); highlight=0; -refresh();} {selected - } +refresh();} {} } Function {refresh()} {} { code {if (bank->emptyslot(nslot)) { @@ -254,9 +252,7 @@ if ((what==2)&&(bank->emptyslot(slot)==0)&&(mode!=4)) {//Rename slot }; if ((what==1)&&(mode==1)&&(!bank->emptyslot(slot))){//Reads from slot - pthread_mutex_lock(&master->mutex); bank->loadfromslot(slot,master->part[*npart]); - pthread_mutex_unlock(&master->mutex); master->part[*npart]->applyparameters(); snprintf((char *)master->part[*npart]->Pname,PART_MAX_NAME_LEN,"%s",bank->getname(slot)); cbwig->do_callback(); @@ -305,7 +301,8 @@ if (mode==4){//swap bs[slot]->refresh(); }; }; -if (mode!=4) refreshmainwindow();} {} +if (mode!=4) refreshmainwindow();} {selected + } } Function {refreshmainwindow()} {} { code {bankuiwindow->label(bank->bankfiletitle);