Subversion Repositories svn.mios32

Rev

Rev 1190 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1003 tk 1
/* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
2
// $Id: OscMonitor.cpp 1724 2013-03-28 20:23:40Z tk $
3
/*
4
 * OSC Monitor Component
5
 *
6
 * ==========================================================================
7
 *
8
 *  Copyright (C) 2010 Thorsten Klose (tk@oscbox.org)
9
 *  Licensed for personal non-commercial use only.
10
 *  All other rights reserved.
11
 *
12
 * ==========================================================================
13
 */
14
 
15
#include "OscMonitor.h"
16
#include "MiosStudio.h"
17
 
18
//==============================================================================
19
OscMonitor::OscMonitor(MiosStudio *_miosStudio)
20
    : miosStudio(_miosStudio)
21
{
22
    addAndMakeVisible(displayOptionsLabel = new Label(String::empty, T("OSC Display Options:")));
23
    displayOptionsLabel->setJustificationType(Justification::right);
24
    addAndMakeVisible(displayOptionsComboBox = new ComboBox(String::empty));
25
    displayOptionsComboBox->setWantsKeyboardFocus(true);
26
    displayOptionsComboBox->addItem(T("Decoded Text only"), 1);
27
    displayOptionsComboBox->addItem(T("Hex dump only"), 2);
28
    displayOptionsComboBox->addItem(T("Decoded Text and Hex Dump"), 3);
29
    displayOptionsComboBox->setSelectedId(1, true);
1006 tk 30
    displayOptionsComboBox->addListener(this);
1003 tk 31
 
32
    addAndMakeVisible(monitorLogBox = new LogBox(T("Osc Monitor")));
33
    monitorLogBox->addEntry(Colours::grey, T("OSC Monitor ready."));
34
 
35
    // restore settings
1724 tk 36
    PropertiesFile *propertiesFile = MiosStudioProperties::getInstance()->getCommonSettings(true);
1003 tk 37
    if( propertiesFile ) {
38
        displayOptionsComboBox->setSelectedId(propertiesFile->getIntValue(T("oscDisplayOption")), true);
39
    }
40
 
41
    setSize(400, 200);
42
}
43
 
44
OscMonitor::~OscMonitor()
45
{
46
}
47
 
48
//==============================================================================
49
void OscMonitor::paint (Graphics& g)
50
{
51
    g.fillAll(Colours::white);
52
}
53
 
54
void OscMonitor::resized()
55
{
56
    displayOptionsLabel->setBounds(4, 4, 150, 24);
57
    displayOptionsComboBox->setBounds(4+150+10, 4, 250, 24);
58
 
59
    monitorLogBox->setBounds(4, 4+24+4, getWidth()-8, getHeight()-(4+24+4+4));
60
}
61
 
62
 
63
//==============================================================================
64
void OscMonitor::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
65
{
66
    if( comboBoxThatHasChanged == displayOptionsComboBox ) {
1724 tk 67
        PropertiesFile *propertiesFile = MiosStudioProperties::getInstance()->getCommonSettings(true);
1003 tk 68
        if( propertiesFile ) {
69
            propertiesFile->setValue(T("oscDisplayOption"), String(displayOptionsComboBox->getSelectedId()));
70
        }
71
    }
72
}
73
 
74
//==============================================================================
1005 tk 75
void OscMonitor::parsedOscPacket(const OscHelper::OscArgsT& oscArgs, const unsigned& methodArg)
76
{
77
    if( oscString == String::empty )
78
        oscString = T("@") + String::formatted(T("%d.%d "), oscArgs.timetag.seconds, oscArgs.timetag.fraction);
79
    else
80
        oscString += " ";
81
 
82
    oscString += OscHelper::element2String(oscArgs);
83
}
84
 
85
 
86
//==============================================================================
1003 tk 87
void OscMonitor::handleIncomingOscMessage(const unsigned char *message, unsigned size)
88
{
89
    double timeStamp = ((double)Time::getMillisecondCounter() / 1000.0);
90
    String timeStampStr = String::formatted(T("%8.3f"), timeStamp);
91
 
1005 tk 92
    unsigned displayOption = displayOptionsComboBox->getSelectedId();
93
 
94
    if( displayOption >= 2 ) {
95
        String hexStr = String::toHexString(message, size);
96
        monitorLogBox->addEntry(Colours::black, "[" + timeStampStr + "] " + hexStr);
97
    }
98
 
99
    if( displayOption == 1 || displayOption == 3 ) {
100
        oscString = String::empty;
101
        OscHelper::OscSearchTreeT searchTree[] = {
102
            //{ "midi", NULL, this, 0x00000000 },
103
            { NULL, NULL, this, 0 } // terminator - will receive all messages that haven't been parsed
104
        };
105
 
106
        int status = OscHelper::parsePacket((unsigned char *)message, size, searchTree);
107
        if( status == -1 )
108
            monitorLogBox->addEntry(Colours::red, "[" + timeStampStr + "] received packet with invalid format!");
109
        else if( status == -2 )
110
            monitorLogBox->addEntry(Colours::red, "[" + timeStampStr + "] received packet with invalid element format!");
111
        else if( status == -3 )
112
            monitorLogBox->addEntry(Colours::red, "[" + timeStampStr + "] received packet with unsupported format!");
113
        else if( status == -4 )
114
            monitorLogBox->addEntry(Colours::red, "[" + timeStampStr + "] MIOS32_OSC_MAX_PATH_PARTS has been exceeded!");
115
        else if( status == -5 )
116
            monitorLogBox->addEntry(Colours::red, "[" + timeStampStr + "] received erroneous packet with status " + String(status));
117
        else if( oscString == String::empty )
118
            monitorLogBox->addEntry(Colours::red, "[" + timeStampStr + "] received empty OSC packet (check hex view!)");
119
        else
120
            monitorLogBox->addEntry(Colours::blue, "[" + timeStampStr + "] " + oscString);
121
    }
1003 tk 122
}