Subversion Repositories svn.mios32

Rev

Rev 889 | Rev 908 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
877 tk 1
/* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
2
// $Id: MidiMonitor.cpp 894 2010-02-10 00:17:16Z tk $
3
/*
4
 * MIDI Monitor Component
5
 *
6
 * ==========================================================================
7
 *
8
 *  Copyright (C) 2010 Thorsten Klose (tk@midibox.org)
9
 *  Licensed for personal non-commercial use only.
10
 *  All other rights reserved.
11
 *
12
 * ==========================================================================
13
 */
14
 
15
#include "MidiMonitor.h"
878 tk 16
#include "MiosStudio.h"
877 tk 17
 
18
 
19
//==============================================================================
878 tk 20
MidiMonitor::MidiMonitor(MiosStudio *_miosStudio, const bool _inPort)
21
    : miosStudio(_miosStudio)
877 tk 22
    , inPort(_inPort)
878 tk 23
    , gotFirstMessage(0)
24
    , filterMidiClock(1)
25
    , filterActiveSense(1)
26
    , filterMiosTerminalMessage(1)
886 tk 27
    , cutLongMessages(1)
877 tk 28
{
29
    addAndMakeVisible(midiPortSelector = new ComboBox(String::empty));
30
    midiPortSelector->addListener(this);
31
    midiPortSelector->clear();
32
    midiPortSelector->addItem (TRANS("<< none >>"), -1);
33
    midiPortSelector->addSeparator();
34
 
35
    const StringArray midiPorts = inPort ? MidiInput::getDevices() : MidiOutput::getDevices();
36
 
37
    int current = -1;
38
    for(int i = 0; i < midiPorts.size(); ++i) {
39
        midiPortSelector->addItem (midiPorts[i], i + 1);
40
        bool enabled = inPort
878 tk 41
            ? miosStudio->audioDeviceManager.isMidiInputEnabled(midiPorts[i])
42
            : (miosStudio->audioDeviceManager.getDefaultMidiOutputName() == midiPorts[i]);
877 tk 43
 
44
        if( enabled )
45
            current = i + 1;
46
    }
47
    midiPortSelector->setSelectedId(current, true);
48
 
49
    midiPortLabel = new Label("", inPort ? T("MIDI IN: ") : T("MIDI OUT: "));
50
    midiPortLabel->attachToComponent(midiPortSelector, true);
51
 
894 tk 52
    addAndMakeVisible(monitorLogBox = new LogBox(T("Midi Monitor")));
53
    monitorLogBox->addEntry(T("MIDI Monitor ready."));
877 tk 54
 
55
    setSize(400, 200);
56
}
57
 
58
MidiMonitor::~MidiMonitor()
59
{
894 tk 60
    deleteAndZero(monitorLogBox);
877 tk 61
}
62
 
63
//==============================================================================
64
void MidiMonitor::paint (Graphics& g)
65
{
66
    g.fillAll(Colours::white);
67
}
68
 
69
void MidiMonitor::resized()
70
{
71
    midiPortLabel->setBounds(4, 4, 50-8, 22);
72
    midiPortSelector->setBounds(4+50+4, 4, getWidth()-8-50-4, 22);
894 tk 73
    monitorLogBox->setBounds(4, 4+22+4, getWidth()-8, getHeight()-(4+22+4+4));
877 tk 74
}
75
 
76
 
77
//==============================================================================
78
void MidiMonitor::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
79
{
80
    if( comboBoxThatHasChanged == midiPortSelector ) {
878 tk 81
        if( inPort )
82
            miosStudio->setMidiInput(midiPortSelector->getText());
83
        else
84
            miosStudio->setMidiOutput(midiPortSelector->getText());
877 tk 85
    }
86
}
87
 
88
//==============================================================================
878 tk 89
void MidiMonitor::handleIncomingMidiMessage(const MidiMessage& message, uint8 runningStatus)
877 tk 90
{
886 tk 91
    uint32 size = message.getRawDataSize();
878 tk 92
    uint8 *data = message.getRawData();
877 tk 93
 
886 tk 94
    String hexStr;
95
    if( cutLongMessages && size > 16 )
96
        hexStr = String::toHexString(data, 16) + " ...";
97
    else
98
        hexStr = String::toHexString(data, size);
99
 
878 tk 100
    bool isMidiClock = data[0] == 0xf8;
101
    bool isActiveSense = data[0] == 0xfe;
886 tk 102
    bool isMiosTerminalMessage = SysexHelper::isValidMios32DebugMessage(data, size, -1);
878 tk 103
 
104
    if( !(isMidiClock && filterMidiClock) &&
105
        !(isActiveSense && filterActiveSense) &&
106
        !(isMiosTerminalMessage && filterMiosTerminalMessage) ) {
107
 
108
        if( !gotFirstMessage )
894 tk 109
            monitorLogBox->clear();
878 tk 110
 
111
        double timeStamp = message.getTimeStamp();
112
        String timeStampStr = (timeStamp > 0)
113
            ? String::formatted(T("%8.3f"), timeStamp)
114
            : T("now");
115
 
894 tk 116
        monitorLogBox->addEntry("[" + timeStampStr + "] " + hexStr);
878 tk 117
        gotFirstMessage = 1;
118
    }
877 tk 119
}