My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
157
package de.derhess.projects.air_MaxFlashHarmony
{
import com.demonsters.debugger.MonsterDebugger;

import de.derhess.drawing.brushes.RibbonBrush;
import de.derhess.drawing.brushes.SimpleBrush;
import de.derhess.drawing.brushes.SquaresBrush;

import flash.desktop.NativeApplication;
import flash.display.Sprite;
import flash.events.Event;

import org.tuio.connectors.UDPConnector;
import org.tuio.osc.OSCManager;
import org.tuio.osc.OSCMessage;

[SWF(width="1200", height="700", frameRate="30", backgroundColor="#FFFFFF")]
public class as3_MaxFlashHarmony extends Sprite implements IHarmonyApp
{
//--------------------------------------------------------------------------
//
// Class variables
//
//--------------------------------------------------------------------------

//--------------------------------------------------------------------------
//
// Variables
//
//--------------------------------------------------------------------------
private var oscListener:HarmonyOSCListener;
private var oscManager:OSCManager;
private var receiver:UDPConnector;
private var sender:UDPConnector;

private var canvas:HarmonyCanvas

private var voiceX:int;
private var voiceY:int;
private var violineX:int;
private var violineY:int;

private var voiceBrush:RibbonBrush;
private var violineBrush:RibbonBrush;
//--------------------------------------------------------------------------
//
// Initialization
//
//--------------------------------------------------------------------------
public function as3_MaxFlashHarmony()
{
super();
// Air stuff
this.stage.nativeWindow.visible = true;
NativeApplication.nativeApplication.addEventListener(Event.EXITING,handleExiting);

// Start Debugging
MonsterDebugger.initialize(this);
MonsterDebugger.trace(this, "Hello Air!");

// GUI
canvas = new HarmonyCanvas(1200,700);
addChild(canvas);
voiceBrush = new RibbonBrush(canvas.drawing,this.stage.width/2,this.stage.height/2);
voiceBrush.style.color = 0xDD0000;
voiceBrush.strokeStart(this.stage.width/2,this.stage.height/2);
violineBrush = new RibbonBrush(canvas.drawing,this.stage.width/2,this.stage.height/2);
violineBrush.style.color = 0x00DD00;
violineBrush.strokeStart(this.stage.width/2,this.stage.height/2);

// Set up OSC
oscListener = new HarmonyOSCListener();
oscListener.app = this;
receiver = new UDPConnector("127.0.0.1",9001,true);
sender = new UDPConnector("127.0.0.1", 9000, false);
oscManager = new OSCManager(receiver, sender,false);
oscManager.addMsgListener(oscListener)
oscManager.start();
}
//--------------------------------------------------------------------------
//
// Properties
//
//--------------------------------------------------------------------------

//--------------------------------------------------------------------------
//
// Additional getters and setters
//
//--------------------------------------------------------------------------

//--------------------------------------------------------------------------
//
// Methods
//
//--------------------------------------------------------------------------
private function renderDrawing():void
{
// save the drawing in a bitmapData Object for performance
canvas.bmpCanvas.draw(canvas.drawing);
// clean the canvas again for new drawings. Too much drawing decrease the performance very fast
canvas.drawing.graphics.clear();
}
//--------------------------------------------------------------------------
//
// API
//
//--------------------------------------------------------------------------
public function updateOSCData(msg:OSCMessage):void
{
if(msg.address == "/cursor/voice") {
//trace("draw voice brush " + msg.arguments[0] + "/" + msg.arguments[1]);
if(voiceX != msg.arguments[0] || voiceY != msg.arguments[1]) {
voiceX = int(msg.arguments[0]);
voiceY = int(msg.arguments[1]);
//trace("Voice: " + voiceX + " / " + voiceY);
voiceBrush.stroke(voiceX,voiceY);
}
}

if(msg.address == "/cursor/violine") {
//trace("draw voice brush " + msg.arguments[0] + "/" + msg.arguments[1]);
if(violineX != msg.arguments[0] || violineY != msg.arguments[1]) {
violineX = int(msg.arguments[0]);
violineY = int(msg.arguments[1]);
//trace("Violine: " + violineX + " / " + violineY);
violineBrush.stroke(violineX,violineY);
}
}

// Appears when the musician makes a big change in the style of playing the instrument
if(msg.address == "/attack/voice" || msg.address == "/attack/violine") {
MonsterDebugger.trace(this,"ATTACK!!");
}

renderDrawing();
}
//--------------------------------------------------------------------------
//
// Eventhandling
//
//--------------------------------------------------------------------------

private function handleExiting(event:Event):void
{
MonsterDebugger.trace(this,"exit Application");
receiver.close();
oscManager.stop();
}

//--------------------------------------------------------------------------
//
// Broadcasting
//
//--------------------------------------------------------------------------
}
}

Change log

r39 by Florian....@derhess.de on Aug 15, 2011   Diff
added Flash to Max/Msp project files
- air_MaxFlashHarmony
- air_flashToMaxMSP
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 5456 bytes, 157 lines
Powered by Google Project Hosting