File: beep_ui.cpp

package info (click to toggle)
lvtk 1.2.0~dfsg0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,308 kB
  • ctags: 2,439
  • sloc: python: 13,036; cpp: 5,029; makefile: 42; ansic: 15
file content (76 lines) | stat: -rw-r--r-- 2,135 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
  beep_ui.cpp  -  LV2 Toolkit API Demonstration Plugin

  Copyright (C) 2004-2010  Lars Luthman
  Updated for LVTK by Michael Fisher <mfisher31@gmail.com>

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License as
  published by the Free Software Foundation; either version 2 of
  the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include <lvtk/gtkui.hpp>
#include "beep.h"


using namespace sigc;
using namespace Gtk;


/* An atom-like struct for raw MIDI note on/offs */
struct midi_t {
    LV2_Atom atom;
    uint8_t midi[3];
};


class BeepGUI : public lvtk::UI<BeepGUI, lvtk::GtkUI<true>, lvtk::URID<true> > {
public:
  
    BeepGUI(const char* URI) : m_button("Click me!")
    {
        m_button.signal_pressed().connect(
                mem_fun(*this, &BeepGUI::send_note_on));
        m_button.signal_released().connect(
                mem_fun(*this, &BeepGUI::send_note_off));
        add (m_button);
    }
  
protected:
  
    /* Raw MIDI Senders */

    void send_note_on()
    {
        LV2_URID xfer = map(LV2_ATOM__eventTransfer);
        LV2_URID midiEvent = map(LV2_MIDI__MidiEvent);

        midi_t midi = {{3, midiEvent}, { 0x90, 0x40, 0x40 }};
        write (p_midi, sizeof(midi), xfer, (void*)&midi);
    }

    void send_note_off()
    {
        LV2_URID xfer = map(LV2_ATOM__eventTransfer);
        LV2_URID midiEvent = map(LV2_MIDI__MidiEvent);

        midi_t midi = {{3, midiEvent},{ 0x80, 0x40, 0x40 }};
        write (p_midi, sizeof(midi), xfer, (void*)&midi);
    }

    Button m_button;
  
};

static int _ = BeepGUI::register_class ("http://ll-plugins.nongnu.org/lv2/lv2pftci/beep/gui");