Subversion Repositories svn.mios32

Rev

Rev 1726 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1726 Rev 1734
1
/* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
1
/* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
2
// $Id: MiosTerminal.cpp 1726 2013-03-28 21:20:34Z tk $
2
// $Id: MiosTerminal.cpp 1734 2013-04-05 21:19:53Z tk $
3
/*
3
/*
4
 * MIOS Terminal Component
4
 * MIOS Terminal Component
5
 *
5
 *
6
 * ==========================================================================
6
 * ==========================================================================
7
 *
7
 *
8
 *  Copyright (C) 2010 Thorsten Klose (tk@midibox.org)
8
 *  Copyright (C) 2010 Thorsten Klose (tk@midibox.org)
9
 *  Licensed for personal non-commercial use only.
9
 *  Licensed for personal non-commercial use only.
10
 *  All other rights reserved.
10
 *  All other rights reserved.
11
 *
11
 *
12
 * ==========================================================================
12
 * ==========================================================================
13
 */
13
 */
14
14
15
#include "MiosTerminal.h"
15
#include "MiosTerminal.h"
16
#include "MiosStudio.h"
16
#include "MiosStudio.h"
17
17
18
18
19
//==============================================================================
19
//==============================================================================
20
MiosTerminal::MiosTerminal(MiosStudio *_miosStudio)
20
MiosTerminal::MiosTerminal(MiosStudio *_miosStudio)
21
    : miosStudio(_miosStudio)
21
    : miosStudio(_miosStudio)
22
    , gotFirstMessage(0)
22
    , gotFirstMessage(0)
23
{
23
{
24
    addAndMakeVisible(terminalLogBox = new LogBox(T("MIOS Terminal")));
24
    addAndMakeVisible(terminalLogBox = new LogBox(T("MIOS Terminal")));
25
    terminalLogBox->addEntry(Colours::grey, T("MIOS Terminal ready."));
25
    terminalLogBox->addEntry(Colours::grey, T("MIOS Terminal ready."));
26
26
27
    addAndMakeVisible(inputLine = new TextEditor(String::empty));
27
    addAndMakeVisible(inputLine = new CommandLineEditor());
28
    inputLine->setMultiLine(false);
-
 
29
    inputLine->setReturnKeyStartsNewLine(false);
-
 
30
    inputLine->setReadOnly(false);
-
 
31
    inputLine->setScrollbarsShown(false);
-
 
32
    inputLine->setCaretVisible(true);
-
 
33
    inputLine->setPopupMenuEnabled(true);
-
 
34
    inputLine->setTextToShowWhenEmpty(T("(send a command to MIOS32 application)"), Colours::grey);
28
    inputLine->setTextToShowWhenEmpty(T("(send a command to MIOS32 application)"), Colours::grey);
35
    inputLine->addListener(this);
29
    inputLine->addListener(this);
36
30
37
    setSize(400, 200);
31
    setSize(400, 200);
38
}
32
}
39
33
40
MiosTerminal::~MiosTerminal()
34
MiosTerminal::~MiosTerminal()
41
{
35
{
42
}
36
}
43
37
44
//==============================================================================
38
//==============================================================================
45
void MiosTerminal::paint (Graphics& g)
39
void MiosTerminal::paint (Graphics& g)
46
{
40
{
47
    g.fillAll(Colours::white);
41
    g.fillAll(Colours::white);
48
}
42
}
49
43
50
void MiosTerminal::resized()
44
void MiosTerminal::resized()
51
{
45
{
52
    terminalLogBox->setBounds(4, 4, getWidth()-8, getHeight()-8-24-4);
46
    terminalLogBox->setBounds(4, 4, getWidth()-8, getHeight()-8-24-4);
53
    inputLine->setBounds(4, getHeight()-4-24, getWidth()-8, 24);
47
    inputLine->setBounds(4, getHeight()-4-24, getWidth()-8, 24);
54
}
48
}
55
49
56
//==============================================================================
50
//==============================================================================
57
void MiosTerminal::textEditorTextChanged(TextEditor &editor)
51
void MiosTerminal::textEditorTextChanged(TextEditor &editor)
58
{
52
{
59
}
53
}
60
54
61
void MiosTerminal::textEditorReturnKeyPressed(TextEditor &editor)
55
void MiosTerminal::textEditorReturnKeyPressed(TextEditor &editor)
62
{
56
{
63
    if( &editor == inputLine ) {
57
    if( &editor == inputLine ) {
64
        String command = inputLine->getText();
58
        String command = inputLine->getText();
65
59
66
        Array<uint8> dataArray = SysexHelper::createMios32DebugMessage(miosStudio->uploadHandler->getDeviceId());
60
        Array<uint8> dataArray = SysexHelper::createMios32DebugMessage(miosStudio->uploadHandler->getDeviceId());
67
        dataArray.add(0x00); // input string
61
        dataArray.add(0x00); // input string
68
        for(int i=0; i<command.length(); ++i)
62
        for(int i=0; i<command.length(); ++i)
69
            dataArray.add(command[i] & 0x7f);
63
            dataArray.add(command[i] & 0x7f);
70
        dataArray.add('\n');
64
        dataArray.add('\n');
71
        dataArray.add(0xf7);
65
        dataArray.add(0xf7);
72
        MidiMessage message = SysexHelper::createMidiMessage(dataArray);
66
        MidiMessage message = SysexHelper::createMidiMessage(dataArray);
73
        miosStudio->sendMidiMessage(message);
67
        miosStudio->sendMidiMessage(message);
74
68
75
        inputLine->setText(String::empty);
69
        inputLine->setText(String::empty);
76
70
77
        if( !gotFirstMessage )
71
        if( !gotFirstMessage )
78
            terminalLogBox->clear();
72
            terminalLogBox->clear();
79
        gotFirstMessage = 1;
73
        gotFirstMessage = 1;
80
74
81
#if 0
75
#if 0
82
        String timeStampStr = T("input");
76
        String timeStampStr = T("input");
83
#else
77
#else
84
        double timeStamp = Time::getMillisecondCounter() / 1000.0; // Note: it's intented that this is the system up time
78
        double timeStamp = Time::getMillisecondCounter() / 1000.0; // Note: it's intented that this is the system up time
85
        String timeStampStr = (timeStamp > 0)
79
        String timeStampStr = (timeStamp > 0)
86
            ? String::formatted(T("%8.3f"), timeStamp)
80
            ? String::formatted(T("%8.3f"), timeStamp)
87
            : T("now");
81
            : T("now");
88
#endif
82
#endif
89
        terminalLogBox->addEntry(Colours::grey, "[" + timeStampStr + "] " + command);
83
        terminalLogBox->addEntry(Colours::grey, "[" + timeStampStr + "] " + command);
90
    }
84
    }
91
}
85
}
92
86
93
void MiosTerminal::textEditorEscapeKeyPressed(TextEditor &editor)
87
void MiosTerminal::textEditorEscapeKeyPressed(TextEditor &editor)
94
{
88
{
95
    if( &editor == inputLine ) {
-
 
96
        inputLine->setText(String::empty);
89
    editor.setText(String::empty);
97
    }
-
 
98
}
90
}
99
91
100
void MiosTerminal::textEditorFocusLost(TextEditor &editor)
92
void MiosTerminal::textEditorFocusLost(TextEditor &editor)
101
{
93
{
102
}
94
}
103
95
104
96
105
//==============================================================================
97
//==============================================================================
106
void MiosTerminal::handleIncomingMidiMessage(const MidiMessage& message, uint8 runningStatus)
98
void MiosTerminal::handleIncomingMidiMessage(const MidiMessage& message, uint8 runningStatus)
107
{
99
{
108
    uint8 *data = (uint8 *)message.getRawData();
100
    uint8 *data = (uint8 *)message.getRawData();
109
    uint32 size = message.getRawDataSize();
101
    uint32 size = message.getRawDataSize();
110
    int messageOffset = 0;
102
    int messageOffset = 0;
111
103
112
    bool messageReceived = false;
104
    bool messageReceived = false;
113
    if( runningStatus == 0xf0 &&
105
    if( runningStatus == 0xf0 &&
114
        SysexHelper::isValidMios32DebugMessage(data, size, -1) &&
106
        SysexHelper::isValidMios32DebugMessage(data, size, -1) &&
115
        (data[7] == 0x40 || data[7] == 0x00) ) { // allow 0x40 (received) and 0x00 (sent) terminal message
107
        (data[7] == 0x40 || data[7] == 0x00) ) { // allow 0x40 (received) and 0x00 (sent) terminal message
116
                                                 // 0x00 is allowed for the "feedback test" which is described in the MIDI troubleshooting guide
108
                                                 // 0x00 is allowed for the "feedback test" which is described in the MIDI troubleshooting guide
117
            messageOffset = 8;
109
            messageOffset = 8;
118
            messageReceived = true;
110
            messageReceived = true;
119
    }
111
    }
120
112
121
    if( messageReceived ) {
113
    if( messageReceived ) {
122
        String str = "";
114
        String str = "";
123
115
124
        for(int i=messageOffset; i<size; ++i) {
116
        for(int i=messageOffset; i<size; ++i) {
125
            if( data[i] < 0x80 ) {
117
            if( data[i] < 0x80 ) {
126
                if( data[i] != '\n' || size < (i+1) )
118
                if( data[i] != '\n' || size < (i+1) )
127
                    str += String::formatted(T("%c"), data[i] & 0x7f);
119
                    str += String::formatted(T("%c"), data[i] & 0x7f);
128
            }
120
            }
129
        }
121
        }
130
122
131
        if( !gotFirstMessage )
123
        if( !gotFirstMessage )
132
            terminalLogBox->clear();
124
            terminalLogBox->clear();
133
        gotFirstMessage = 1;
125
        gotFirstMessage = 1;
134
126
135
        double timeStamp = message.getTimeStamp() ? message.getTimeStamp() : ((double)Time::getMillisecondCounter() / 1000.0);
127
        double timeStamp = message.getTimeStamp() ? message.getTimeStamp() : ((double)Time::getMillisecondCounter() / 1000.0);
136
        String timeStampStr = (timeStamp > 0)
128
        String timeStampStr = (timeStamp > 0)
137
            ? String::formatted(T("%8.3f"), timeStamp)
129
            ? String::formatted(T("%8.3f"), timeStamp)
138
            : T("now");
130
            : T("now");
139
131
140
        terminalLogBox->addEntry(Colours::black, "[" + timeStampStr + "] " + str);
132
        terminalLogBox->addEntry(Colours::black, "[" + timeStampStr + "] " + str);
141
    }
133
    }
142
}
134
}
143
 
135