1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ 2 /* 3 * so-kl5.h 4 * 5 * Copyright (C) 2011 - Jeremy Salwen 6 * Copyright (C) 2010 - 50m30n3 7 * Copyright (C) 2020 - Google LLC 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 #include <lv2.h> 24 #include <math.h> 25 #include <stdio.h> 26 #include <stdlib.h> 27 #include <string.h> 28 #include <unistd.h> 29 30 #include "lv2/lv2plug.in/ns/ext/atom/atom.h" 31 #include "lv2/lv2plug.in/ns/ext/atom/util.h" 32 #include "lv2/lv2plug.in/ns/ext/midi/midi.h" 33 #include "lv2/lv2plug.in/ns/ext/urid/urid.h" 34 35 #define NUMNOTES 80 36 #define BASENOTE 21 37 38 #define MIDI_COMMANDMASK 0xF0 39 #define MIDI_CHANNELMASK 0x0F 40 41 #define MIDI_NOTEON 0x90 42 #define MIDI_NOTEOFF 0x80 43 #define MIDI_CONTROL 0xB0 44 45 enum KL5_PORTS { 46 KL5_PORT_OUTPUT = 0, 47 KL5_PORT_MIDI, 48 KL5_PORT_CONTROLMODE, 49 KL5_PORT_SUSTAIN, 50 KL5_PORT_RESONANCE, 51 KL5_PORT_CUTOFF, 52 KL5_PORT_ATTACK, 53 KL5_PORT_VOLUME, 54 KL5_PORT_CHANNEL 55 }; 56 57 void runSO_kl5(LV2_Handle arg, uint32_t nframes); 58 LV2_Handle instantiateSO_kl5(const LV2_Descriptor* descriptor, double s_rate, 59 const char* path, 60 const LV2_Feature* const* features); 61 void cleanupSO_kl5(LV2_Handle instance); 62 void connectPortSO_kl5(LV2_Handle instance, uint32_t port, void* data_location); 63 64 static LV2_Descriptor so_kl5_Descriptor = { 65 .URI = "urn:50m30n3:plugins:SO-kl5", 66 .instantiate = instantiateSO_kl5, 67 .connect_port = connectPortSO_kl5, 68 .activate = NULL, 69 .run = runSO_kl5, 70 .deactivate = NULL, 71 .cleanup = cleanupSO_kl5, 72 .extension_data = NULL, 73 }; 74 75 typedef struct so_kl5_t { 76 float* output; 77 78 struct { 79 LV2_URID midi_MidiEvent; 80 } uris; 81 82 const LV2_Atom_Sequence* midi_p; 83 float* controlmode_p; 84 float* volume_p; 85 float* resonance_p; 86 float* cutoff_p; 87 float* sustain_p; 88 float* attack_p; 89 90 float* strings[NUMNOTES]; 91 unsigned int stringpos[NUMNOTES]; 92 unsigned int stringlength[NUMNOTES]; 93 float stringcutoff[NUMNOTES]; 94 int status[NUMNOTES]; 95 96 unsigned int volume; 97 98 float lpval, lplast; 99 float fcutoff, freso, ssustain, sattack; 100 101 float* channel_p; 102 103 float* tempstring; 104 } so_kl5; 105