Portamento.h (4040B)
1 /* 2 ZynAddSubFX - a software synthesizer 3 4 Portamento.h - Portamento calculation and management 5 Copyright (C) 2021 Mark McCurry 6 Author: Mark McCurry 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 #ifndef PORTAMENTO_H 14 #define PORTAMENTO_H 15 #include "../globals.h" 16 #include "../Params/Controller.h" 17 #include <functional> 18 19 namespace zyn { 20 21 // Realtime struct governing portamento. Read by synth engines, 22 // created and managed by parts. 23 class Portamento { 24 public: 25 /** 26 * Create a portamento. 27 * Sets the active member if the portemento is activated. 28 * 29 * @param ctl The Controller which contains user patch parameters 30 * @param synth The SYNTH_T from which to get sample rate and bufsize 31 * @param is_running_note True if at least one note is playing 32 * @param oldfreq_log2 Pitch of previous note 33 * @param oldportamentofreq_log2 Starting pitch of the portamento 34 * @param newfreq_log2 Ending pitch of the portamento 35 */ 36 Portamento(const Controller &ctl, 37 const SYNTH_T &synth, 38 bool is_running_note, 39 float oldfreq_log2, 40 float oldportamentofreq_log2, 41 float newfreq_log2); 42 /** 43 * Initialize an already existing portamento. 44 * Sets the active member if the portemento is activated. 45 * 46 * @param ctl The Controller which contains user patch parameters 47 * @param synth The SYNTH_T from which to get sample rate and bufsize 48 * @param is_running_note True if at least one note is playing 49 * @param oldfreq_log2 Pitch of previous note 50 * @param oldportamentofreq_log2 Starting pitch of the portamento 51 * @param newfreq_log2 Ending pitch of the portamento 52 */ 53 void init(const Controller &ctl, 54 const SYNTH_T &synth, 55 bool is_running_note, 56 float oldfreq_log2, 57 float oldportamentofreq_log2, 58 float newfreq_log2); 59 /**Update portamento's freqrap to next value based upon dx*/ 60 void update(void); 61 /**if the portamento is in use*/ 62 bool active; 63 /**this value is used to compute the actual portamento 64 * 65 * This is the logarithmic power of two frequency 66 * adjustment of the newer frequency to fit the profile of 67 * the portamento. 68 * This will be linear with respect to x.*/ 69 float freqdelta_log2; 70 71 private: 72 /**x is from 0.0f (start portamento) to 1.0f (finished portamento)*/ 73 float x; 74 /**dx is the increment to x when update is called*/ 75 float dx; 76 /** this is used for computing freqdelta_log2 value from x*/ 77 float origfreqdelta_log2; 78 }; 79 80 class PortamentoRealtime { 81 public: 82 /** 83 * Create a portamento realtime structure. 84 * 85 * @param handle handle to be used by cleanup function 86 * @param memory Allocator used 87 * @param cleanup Callback called from destructor 88 * @param portamento Portamento object to be contained 89 */ 90 PortamentoRealtime(void *handle, 91 Allocator &memory, 92 std::function<void(PortamentoRealtime *)> cleanup, 93 const Portamento &portamento); 94 95 ~PortamentoRealtime(); 96 97 /**handle to be used by cleanup function in lieu of lambda capture*/ 98 void *handle; 99 /**Allocator used to allocate memory*/ 100 Allocator &memory; 101 /**Cleanup callback called by destructor*/ 102 std::function<void(PortamentoRealtime *)> cleanup; 103 /**The actual portamento object*/ 104 Portamento portamento; 105 }; 106 107 } 108 109 #endif /* PORTAMENTO_H */