Debian Codegraph @

plugin/plugingizmo/midievent.cc

raw
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /***************************************************************************
3 * midievent.cc
4 *
5 * Sun Feb 7 15:09:01 CET 2016
6 * Copyright 2016 Bent Bisballe Nyeng
7 * [email protected]
8 ****************************************************************************/
9
10 /*
11 * This file is part of PluginGizmo.
12 *
13 * PluginGizmo is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU Lesser General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * PluginGizmo is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public License
24 * along with PluginGizmo; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 */
27 #include "midievent.h"
28
29 #include <iostream>
30
31 MidiEvent::MidiEvent(int64_t time, const char* data, std::size_t size)
32 : time(time)
33 {
34 //std::cout << __PRETTY_FUNCTION__ <<
35 // " data: " << (void*)data <<
36 // " size: " << size <<
37 // std::endl;
38
39 this->data.resize(size);
40 for(std::size_t i = 0; i < size; ++i)
41 {
42 this->data[i] = data[i];
43 }
44
45 if((data[0] & 0xF0) == 0x80) // note off
46 {
47 type = MidiEventType::NoteOff;
48 key = data[1];
49 velocity = data[2];
50 }
51
52 if((data[0] & 0xF0) == 0x90) // note on
53 {
54 type = MidiEventType::NoteOn;
55 key = data[1];
56 velocity = data[2];
57 }
58
59 if((data[0] & 0xF0) == 0xA0) // aftertouch
60 {
61 type = MidiEventType::Aftertouch;
62 key = data[1];
63 velocity = data[2];
64 }
65 }
66
67 int64_t MidiEvent::getTime() const
68 {
69 return time;
70 }
71
72 const char* MidiEvent::getData() const
73 {
74 return data.data();
75 }
76
77 std::size_t MidiEvent::getSize() const
78 {
79 return data.size();
80 }