Subversion Repositories svn.mios32

Rev

Rev 1189 | 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: OscTextEditor.cpp 2180 2015-06-14 19:21:59Z tk $
3
/*
4
 * Text Editor variant which allows to edit OSC messages
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 "OscTextEditor.h"
16
 
1005 tk 17
#define OSC_BUFFER_MAX 8192
1003 tk 18
 
19
//==============================================================================
20
OscTextEditor::OscTextEditor(Label *_statusLabel)
21
    : TextEditor(String::empty)
22
    , statusLabel(_statusLabel)
23
{
24
    setMultiLine(true);
25
    setReturnKeyStartsNewLine(true);
26
    setReadOnly(false);
27
    setScrollbarsShown(true);
28
    setCaretVisible(true);
29
    setPopupMenuEnabled(true);
30
    //setInputRestrictions(1000000, T("0123456789ABCDEFabcdef \n"));
31
#if JUCE_MAJOR_VERSION==1 && JUCE_MINOR_VERSION<51
1189 tk 32
#if defined(JUCE_WIN32)
1003 tk 33
    setFont(Font(Typeface::defaultTypefaceNameMono, 10.0, 0));
34
#else
35
    setFont(Font(Typeface::defaultTypefaceNameMono, 13.0, 0));
36
#endif
37
#else
1189 tk 38
#if defined(JUCE_WIN32)
1003 tk 39
    setFont(Font(Font::getDefaultMonospacedFontName(), 10.0, 0));
40
#else
41
    setFont(Font(Font::getDefaultMonospacedFontName(), 13.0, 0));
42
#endif
43
#endif
44
    addListener(this);
1006 tk 45
    setTextToShowWhenEmpty(T("Syntax: [@<seconds>.<fraction>] <osc-path> [<arg1>] [<arg2>] ... [<osc-path] [<arg1>] [<arg2>]..."), Colours::grey);
1003 tk 46
 
47
    setSize(600, 200);
48
}
49
 
50
OscTextEditor::~OscTextEditor()
51
{
52
}
53
 
54
//==============================================================================
55
void OscTextEditor::clear()
56
{
57
    TextEditor::clear();
58
}
59
 
60
//==============================================================================
61
void OscTextEditor::textEditorTextChanged(TextEditor &editor)
62
{
1006 tk 63
    String statusMessage;
64
    currentBinary = OscHelper::string2Packet(getText(), statusMessage);
2180 tk 65
    statusLabel->setText(statusMessage, sendNotification);
1003 tk 66
}
67
 
68
void OscTextEditor::textEditorReturnKeyPressed(TextEditor &editor)
69
{
70
}
71
 
72
void OscTextEditor::textEditorEscapeKeyPressed(TextEditor &editor)
73
{
74
}
75
 
76
void OscTextEditor::textEditorFocusLost(TextEditor &editor)
77
{
78
}
79
 
80
 
81
//==============================================================================
82
Array<uint8> OscTextEditor::getBinary(void)
83
{
1006 tk 84
#if 1
85
    return currentBinary;
86
#else
87
    // send dummy message for testing only!
1003 tk 88
    String oscStr = getText();
89
 
1005 tk 90
    uint8 packet[OSC_BUFFER_MAX];
91
    uint8 *endPtr = packet;
92
    uint8 *insertLenPtr;
93
 
94
    OscHelper::OscTimetagT timetag;
95
    timetag.seconds = 0;
96
    timetag.fraction = 0;
97
 
98
    endPtr = OscHelper::putString(endPtr, "#bundle");
99
    endPtr = OscHelper::putTimetag(endPtr, timetag);
100
    insertLenPtr = endPtr; // remember this address - we will insert the length later
101
    endPtr += 4;
102
    endPtr = OscHelper::putString(endPtr, "/foo/bar/xxx/yyy");
103
    endPtr = OscHelper::putString(endPtr, ",fisTF");
104
    endPtr = OscHelper::putFloat(endPtr, 0.123f);
105
    endPtr = OscHelper::putInt(endPtr, 42);
106
    endPtr = OscHelper::putString(endPtr, "Hi!");
107
    OscHelper::putWord(insertLenPtr, (unsigned)(endPtr-insertLenPtr-4));
108
    size_t len = (size_t)(endPtr-packet);
109
 
110
    Array<uint8> retArray(packet, len);
1003 tk 111
    return retArray;
1006 tk 112
#endif
1003 tk 113
}