Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
midiadapter.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2015 Haye Hinrichsen, Christoph Wick
3  *
4  * This file is part of Entropy Piano Tuner.
5  *
6  * Entropy Piano Tuner is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * Entropy Piano Tuner is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * Entropy Piano Tuner. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 //=============================================================================
21 // Midi adapter
22 //=============================================================================
23 
24 #include "midiadapter.h"
25 
26 #include <sstream>
27 
28 #include "../../system/log.h"
29 #include "../../messages/messagehandler.h"
30 #include "../../messages/messagemidievent.h"
31 
32 
33 //-----------------------------------------------------------------------------
34 // Return a list of all available Midi devices
35 //-----------------------------------------------------------------------------
36 
40 
42 {
43  const int ports = GetNumberOfPorts();
44  std::stringstream s;
45  if (ports > 0)
46  {
47  s << GetPortName(0);
48  for (int i = 1; i < GetNumberOfPorts(); ++i) s << ", " << GetPortName(i);
49  return s.str();
50  }
51  else return "No MIDI ports available.";
52 }
53 
54 
55 //-----------------------------------------------------------------------------
56 // Convert the MIDI command byte to a MidiEvent
57 //-----------------------------------------------------------------------------
58 
62 
64 {
65  switch (byte & 0xF0)
66  {
67  case 0x80: return MIDI_KEY_RELEASE;
68  case 0x90: return MIDI_KEY_PRESS;
69  case 0xB0: return MIDI_CONTROL_CHANGE;
70  }
71  return MIDI_UNDEFINED;
72 }
73 
74 
75 //-----------------------------------------------------------------------------
76 // Send MIDI message
77 //-----------------------------------------------------------------------------
78 
83 
84 void MidiAdapter::send (Data &data)
85 {
86  LogI("Midi event with data %d %d %d %lf",
87  (int)(data.event), data.byte1, data.byte2, data.deltatime);
88  MessageHandler::send<MessageMidiEvent>(data);
89 }
double deltatime
Time elapsed since the last MIDI event.
Definition: midiadapter.h:93
MidiEvent event
Midi event, encoded by the enumeration MidiEvent.
Definition: midiadapter.h:90
Midi event when a key is pressed.
Definition: midiadapter.h:71
Midi event for changing voice.
Definition: midiadapter.h:73
void send(Data &data)
Send new MIDI data to the messaging system.
Definition: midiadapter.cpp:84
MidiEvent
Enumeration of the possible MIDI events.
Definition: midiadapter.h:68
int byte1
Data byte, usually representing the MIDI key index.
Definition: midiadapter.h:91
virtual std::string GetPortName(int i)=0
Get the name of device number i (starting with zero)
#define LogI(...)
Definition: log.h:50
Midi event when a key is released.
Definition: midiadapter.h:72
static MidiEvent byteToEvent(int byte)
Convert MIDI code to MidiEvent.
Definition: midiadapter.cpp:63
virtual int GetNumberOfPorts()=0
Get the number of available input devices.
virtual std::string GetPortNames()
Get a list of all available input devices.
Definition: midiadapter.cpp:41
int byte2
Data byte, usually representing the keystroke intensity.
Definition: midiadapter.h:92
Midi event undefined.
Definition: midiadapter.h:70
Structure of the data associated with a MIDI event.
Definition: midiadapter.h:88