Skip to content

Commit ae52c36

Browse files
committed
Import SendNote example from #212, slightly adjusted
Signed-off-by: falkTX <[email protected]>
1 parent 9315bc7 commit ae52c36

File tree

6 files changed

+450
-0
lines changed

6 files changed

+450
-0
lines changed

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ examples: dgl
2525
$(MAKE) all -C examples/Meters
2626
$(MAKE) all -C examples/MidiThrough
2727
$(MAKE) all -C examples/Parameters
28+
$(MAKE) all -C examples/SendNote
2829
$(MAKE) all -C examples/States
2930
ifeq ($(HAVE_CAIRO),true)
3031
$(MAKE) all -C examples/CairoUI
@@ -65,6 +66,7 @@ clean:
6566
$(MAKE) clean -C examples/Meters
6667
$(MAKE) clean -C examples/MidiThrough
6768
$(MAKE) clean -C examples/Parameters
69+
$(MAKE) clean -C examples/SendNote
6870
$(MAKE) clean -C examples/States
6971
$(MAKE) clean -C utils/lv2-ttl-generator
7072
ifneq ($(MACOS_OR_WINDOWS),true)

examples/SendNote/DistrhoPluginInfo.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* DISTRHO Plugin Framework (DPF)
3+
* Copyright (C) 2012-2021 Filipe Coelho <[email protected]>
4+
*
5+
* Permission to use, copy, modify, and/or distribute this software for any purpose with
6+
* or without fee is hereby granted, provided that the above copyright notice and this
7+
* permission notice appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10+
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11+
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12+
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13+
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
#ifndef DISTRHO_PLUGIN_INFO_H_INCLUDED
18+
#define DISTRHO_PLUGIN_INFO_H_INCLUDED
19+
20+
#define DISTRHO_PLUGIN_BRAND "DISTRHO"
21+
#define DISTRHO_PLUGIN_NAME "SendNote"
22+
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/examples/SendNote"
23+
24+
#define DISTRHO_PLUGIN_HAS_UI 1
25+
#define DISTRHO_PLUGIN_HAS_EMBED_UI 1
26+
#define DISTRHO_PLUGIN_IS_RT_SAFE 1
27+
#define DISTRHO_PLUGIN_NUM_INPUTS 0
28+
#define DISTRHO_PLUGIN_NUM_OUTPUTS 1
29+
#define DISTRHO_PLUGIN_WANT_MIDI_INPUT 1
30+
#define DISTRHO_PLUGIN_WANT_MIDI_OUTPUT 0
31+
32+
#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED

examples/SendNote/Makefile

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/make -f
2+
# Makefile for DISTRHO Plugins #
3+
# ---------------------------- #
4+
# Created by falkTX
5+
#
6+
7+
# --------------------------------------------------------------
8+
# Project name, used for binaries
9+
10+
NAME = d_sendNote
11+
12+
# --------------------------------------------------------------
13+
# Files to build
14+
15+
FILES_DSP = \
16+
SendNoteExamplePlugin.cpp
17+
18+
19+
FILES_UI = \
20+
SendNoteExampleUI.cpp
21+
22+
# --------------------------------------------------------------
23+
# Do some magic
24+
25+
include ../../Makefile.plugins.mk
26+
27+
# --------------------------------------------------------------
28+
# Enable all possible plugin types
29+
30+
ifeq ($(HAVE_JACK),true)
31+
ifeq ($(HAVE_OPENGL),true)
32+
TARGETS += jack
33+
endif
34+
endif
35+
36+
ifeq ($(HAVE_OPENGL),true)
37+
TARGETS += lv2_sep
38+
else
39+
TARGETS += lv2_dsp
40+
endif
41+
42+
TARGETS += vst
43+
44+
all: $(TARGETS)
45+
46+
# --------------------------------------------------------------

examples/SendNote/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SendNote example
2+
3+
This example will show how to send MIDI notes in DPF based UIs.<br/>
4+
5+
The UI presents a row of MIDI keys which transmit note events to a synthesizer.
6+
+192
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/*
2+
* DISTRHO Plugin Framework (DPF)
3+
* Copyright (C) 2012-2021 Filipe Coelho <[email protected]>
4+
*
5+
* Permission to use, copy, modify, and/or distribute this software for any purpose with
6+
* or without fee is hereby granted, provided that the above copyright notice and this
7+
* permission notice appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10+
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11+
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12+
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13+
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
#include "DistrhoPlugin.hpp"
18+
19+
#include <cmath>
20+
#include <cstring>
21+
22+
START_NAMESPACE_DISTRHO
23+
24+
// -----------------------------------------------------------------------------------------------------------
25+
26+
/**
27+
Plugin that demonstrates sending notes from the editor in DPF.
28+
*/
29+
class SendNoteExamplePlugin : public Plugin
30+
{
31+
public:
32+
SendNoteExamplePlugin()
33+
: Plugin(0, 0, 0)
34+
{
35+
std::memset(fNotesPlayed, 0, sizeof(fNotesPlayed));
36+
std::memset(fOscillatorPhases, 0, sizeof(fOscillatorPhases));
37+
}
38+
39+
protected:
40+
/* --------------------------------------------------------------------------------------------------------
41+
* Information */
42+
43+
/**
44+
Get the plugin label.
45+
This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
46+
*/
47+
const char* getLabel() const override
48+
{
49+
return "SendNote";
50+
}
51+
52+
/**
53+
Get an extensive comment/description about the plugin.
54+
*/
55+
const char* getDescription() const override
56+
{
57+
return "Plugin that demonstrates sending notes from the editor in DPF.";
58+
}
59+
60+
/**
61+
Get the plugin author/maker.
62+
*/
63+
const char* getMaker() const override
64+
{
65+
return "DISTRHO";
66+
}
67+
68+
/**
69+
Get the plugin homepage.
70+
*/
71+
const char* getHomePage() const override
72+
{
73+
return "https://github.com/DISTRHO/DPF";
74+
}
75+
76+
/**
77+
Get the plugin license name (a single line of text).
78+
For commercial plugins this should return some short copyright information.
79+
*/
80+
const char* getLicense() const override
81+
{
82+
return "ISC";
83+
}
84+
85+
/**
86+
Get the plugin version, in hexadecimal.
87+
*/
88+
uint32_t getVersion() const override
89+
{
90+
return d_version(1, 0, 0);
91+
}
92+
93+
/**
94+
Get the plugin unique Id.
95+
This value is used by LADSPA, DSSI and VST plugin formats.
96+
*/
97+
int64_t getUniqueId() const override
98+
{
99+
return d_cconst('d', 'S', 'N', 'o');
100+
}
101+
102+
/* --------------------------------------------------------------------------------------------------------
103+
* Init and Internal data, unused in this plugin */
104+
105+
void initParameter(uint32_t, Parameter&) override {}
106+
float getParameterValue(uint32_t) const override { return 0.0f;}
107+
void setParameterValue(uint32_t, float) override {}
108+
109+
/* --------------------------------------------------------------------------------------------------------
110+
* Audio/MIDI Processing */
111+
112+
/**
113+
Run/process function for plugins with MIDI input.
114+
This synthesizes the MIDI voices with a sum of sine waves.
115+
*/
116+
void run(const float**, float** outputs, uint32_t frames,
117+
const MidiEvent* midiEvents, uint32_t midiEventCount) override
118+
{
119+
for (uint32_t i = 0; i < midiEventCount; ++i)
120+
{
121+
if (midiEvents[i].size <= 3)
122+
{
123+
uint8_t status = midiEvents[i].data[0];
124+
uint8_t note = midiEvents[i].data[1] & 127;
125+
uint8_t velocity = midiEvents[i].data[2] & 127;
126+
127+
switch (status & 0xf0)
128+
{
129+
case 0x90:
130+
if (velocity != 0)
131+
{
132+
fNotesPlayed[note] = velocity;
133+
break;
134+
}
135+
/* fall through */
136+
case 0x80:
137+
fNotesPlayed[note] = 0;
138+
fOscillatorPhases[note] = 0;
139+
break;
140+
}
141+
}
142+
}
143+
144+
float* const output = outputs[0];
145+
std::memset(output, 0, frames * sizeof(float));
146+
147+
for (uint32_t noteNumber = 0; noteNumber < 128; ++noteNumber)
148+
{
149+
if (fNotesPlayed[noteNumber] == 0)
150+
continue;
151+
152+
float notePitch = 8.17579891564 * std::exp(0.0577622650 * noteNumber);
153+
154+
float phase = fOscillatorPhases[noteNumber];
155+
float timeStep = notePitch / getSampleRate();
156+
float k2pi = 2.0 * M_PI;
157+
float gain = 0.1;
158+
159+
for (uint32_t i = 0; i < frames; ++i)
160+
{
161+
output[i] += gain * std::sin(k2pi * phase);
162+
phase += timeStep;
163+
phase -= (int)phase;
164+
}
165+
166+
fOscillatorPhases[noteNumber] = phase;
167+
}
168+
}
169+
170+
// -------------------------------------------------------------------------------------------------------
171+
172+
private:
173+
uint8_t fNotesPlayed[128];
174+
float fOscillatorPhases[128];
175+
176+
/**
177+
Set our plugin class as non-copyable and add a leak detector just in case.
178+
*/
179+
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SendNoteExamplePlugin)
180+
};
181+
182+
/* ------------------------------------------------------------------------------------------------------------
183+
* Plugin entry point, called by DPF to create a new plugin instance. */
184+
185+
Plugin* createPlugin()
186+
{
187+
return new SendNoteExamplePlugin();
188+
}
189+
190+
// -----------------------------------------------------------------------------------------------------------
191+
192+
END_NAMESPACE_DISTRHO

0 commit comments

Comments
 (0)