forked from jcelerier/qml-creative-controls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OssiaClientExample.qml
156 lines (136 loc) · 4.42 KB
/
OssiaClientExample.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import QtQuick 2.0
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.1
import com.github.jcelerier.CreativeControls 1.0
import Ossia 1.0 as Ossia
/**
* This file presents an example of usage of the controls
* provided by this library, with libossia.
* libossia is a library that provides multiple network and message
* protocols useful for creative coding: MIDI, OSC, OSCQuery, etc.
*
* More information is available on :
* https://github.com/OSSIA/libossia
*
* In the current example, the application we are writing acts as a client:
* that is, it connects to existing adresses / parameters of a remote
* software / hardware.
*/
Page {
header: Text { font.pointSize: 30 ; text: "Client example" }
width: 800
height: 500
id: root
// A midi device to which one can send messages to.
Ossia.MidiSink
{
id: midiOutDevice
// look at the console output to know MIDI devices' port number
// and report the one you want to use below
midiPort: 0
}
Ossia.MidiSource
{
id: midiInDevice
// look at the console output to know MIDI input devices' port number
// and report the one you want to use below
midiPort: 0
}
Ossia.OSCQueryClient
{
id: oscqDevice
// Connect to an OSCQuery server. See for instance OssiaServerExample.qml
// or libossia's oscquery_publication_example
address: "ws://127.0.0.1:5678"
}
Row {
spacing: 100
Column {
AngleSlider
{
id: slider
width: 200
height: 200
Ossia.Binding {
// Scale the angle between 0 - 127
on: 127 * (180 + slider.angle) / 360
// The value changes are sent to CC 34 on channel 1
node: '/1/control/34'
device: midiOutDevice
}
}
Label { text: "To Midi CC 34" }
AngleSlider
{
width: 200
height: 200
angle: 0
Ossia.Writer on angle {
node: '/1/control/13'
device: midiInDevice
}
}
Label { text: "From Midi CC 13" }
}
ColumnLayout {
Joystick
{
id: joystick
width: 200
height: 200
// Modify a single propriety using a property value source
Ossia.Reader on stickR {
node: '/units/float'
device: oscqDevice
}
// /units/vec2 will be updated whenever the bound expression changes
Ossia.Binding {
on: Qt.point(0.5 * (1 + joystick.stickX), 0.5 * (1 + joystick.stickY))
node: '/test/values'
device: oscqDevice
}
}
Label { text: "To OSCQuery server (graph and sliders)" }
Item { height: 50 }
Text {
id: txt
anchors.topMargin: 50
text: "Callback from OSCQuery server (angle slider)"
// This updates the text according to messages sent
// by the remote software
Ossia.Callback
{
device: oscqDevice
onValueChanged: txt.text = "foo " + value.toFixed(2) + " bar"
node: '/test/angle'
}
}
// More concise form using a property value source:
Text {
anchors.topMargin: 50
text: "Callback from OSCQuery server (angle slider)"
Ossia.Writer on text {
node: '/test/angle'
device: oscqDevice
}
}
}
}
Component.onCompleted:
{
// List midi devices
console.log("get MIDI output devices...");
var midi_outs = midiOutDevice.getMIDIOutputDevices();
for(var midi in midi_outs)
console.log("device: '" + midi + "'\t\tport number: ", midi_outs[midi])
// midi_outs[midi] is the value to pass to "midiPort"
console.log("get MIDI input devices...");
var midi_ins = midiInDevice.getMIDIInputDevices();
for(var midi in midi_ins)
console.log("device: '" + midi + "'\t\tport number: ", midi_ins[midi])
// midi_ins[midi] is the value to pass to "midiPort"
// Call this at the end to set-up the connections
oscqDevice.openOSCQueryClient(oscqDevice.address, oscqDevice.localPort)
oscqDevice.remap(root)
}
}