Guitarix
gx_midi_plugin.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, 2010 Hermann Meyer, James Warden, Andreas Degert
3  * Copyright (C) 2011 Pete Shorthose
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  * --------------------------------------------------------------------------
19  *
20  *
21  * This is part of the Guitarix Audio Engine
22  *
23  *
24  *
25  * --------------------------------------------------------------------------
26  */
27 
28 #include "engine.h"
29 
30 namespace gx_engine {
31 
32 /****************************************************************
33  ** class MidiAudioBuffer
34  */
35 
36 static const char *midi_out_groups[] = {
37  "channel_1", N_("Midi Out 1"),
38  "channel_2", N_("Midi Out 2"),
39  "channel_3", N_("Midi Out 3"),
40  "beat_detector", N_("Beat Detector"),
41  0
42  };
43 
45  : PluginDef(),
46  midi(),
47  tuner(t),
48  jack(0),
49  jack_overload(load_off),
50  overload_change(),
51  plugin() {
53  flags = PGN_SNOOP;
54  id = "midi_out";
55  name = N_("Midi Out");
56  groups = midi_out_groups;
57  mono_audio = fill_buffer;
58  set_samplerate = init;
59  activate_plugin = activate;
60  register_params = regparam;
61  plugin.set_pdef(this);
62 }
63 
64 int MidiAudioBuffer::activate(bool start, PluginDef *plugin) {
65 #ifdef USE_MIDI_OUT
66  MidiAudioBuffer& self = *static_cast<MidiAudioBuffer*>(plugin);
67  self.jack_overload = start ? load_low : load_off;
68  self.overload_change();
69  return 0;
70 #else
71  return -1;
72 #endif
73 }
74 
75 void MidiAudioBuffer::fill_buffer(int count, float *input, float*,
76  PluginDef *plugin) {
77  MidiAudioBuffer& self = *static_cast<MidiAudioBuffer*>(plugin);
78  if (!self.jack) {
79  return;
80  }
81  void *buf = self.jack->get_midi_buffer(count);
82  if (buf) {
83  float load = self.jack->get_jcpu_load();
84  Load ol = (load < 65.0 ? load_low : load_high);
85  if (self.jack_overload != ol) {
86  self.jack_overload = ol;
87  self.overload_change();
88  }
89  self.midi.process_midi(count, input, buf, load,
90  self.tuner.get_freq(), self.tuner.get_note());
91  }
92 }
93 
94 void MidiAudioBuffer::init(unsigned int samplingFreq, PluginDef *plugin) {
95  MidiAudioBuffer& self = *static_cast<MidiAudioBuffer*>(plugin);
96  self.midi.init(samplingFreq);
97 }
98 
99 int MidiAudioBuffer::regparam(const ParamReg& reg) {
100  MidiAudioBuffer& self = *static_cast<MidiAudioBuffer*>(reg.plugin);
101  self.midi.register_parameter(reg);
102  return 0;
103 }
104 
105 } // namespace gx_engine
CmdConnection::msg_type start
Definition: jsonrpc.cpp:255
PluginDef * plugin
Definition: gx_plugin.h:123
void set_pdef(PluginDef *p)
#define N_(String)
const char * name
Definition: gx_plugin.h:188
const char ** groups
Definition: gx_plugin.h:189
void * get_midi_buffer(jack_nframes_t nframes)
Definition: gx_jack.cpp:662
#define PLUGINDEF_VERSION
Definition: gx_plugin.h:181
registerfunc register_params
Definition: gx_plugin.h:202
int flags
Definition: gx_plugin.h:185
activatefunc activate_plugin
Definition: gx_plugin.h:201
inifunc set_samplerate
Definition: gx_plugin.h:200
process_mono_audio mono_audio
Definition: gx_plugin.h:197
MidiAudioBuffer(TunerAdapter &t)
int version
Definition: gx_plugin.h:184
void init(int samplingFreq)
void register_parameter(const ParamReg &reg)