-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathx_movie.js
More file actions
201 lines (138 loc) · 3.54 KB
/
x_movie.js
File metadata and controls
201 lines (138 loc) · 3.54 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
autowatch = 1;
inlets = 1;
outlets = 2;
var t;
var state;
var key_32;
var mov;
var hide;
declareattribute('hide');
var pos = 0;
// -------------------------------------------------
// Scaling Functions
// -------------------------------------------------
function normalize(unscaledNum, minAllowed, maxAllowed, newmin, newmax) {
return (maxAllowed - minAllowed) * (unscaledNum - newmin) / (newmax - newmin) + minAllowed;
}
function scaleint(unscaledNum, minAllowed, maxAllowed, newmin, newmax) {
return Math.floor((maxAllowed - minAllowed) * (unscaledNum - newmin) / (newmax - newmin) + minAllowed);
}
function tickstoms(ticks) {
var ms = Math.floor(60000 / (120*480) * ticks);
return ms;
}
// -------------------------------------------------
// Player Functions
// -------------------------------------------------
function init() {
// fileread initializes the variabes
t = this.patcher;
key_32 = t.getnamed('trigspace');
state = t.getnamed('state');
mov = t.getnamed('movie');
}
function fileread() {
init();
var d_movfps = t.getnamed('display_moviefps');
var d_movdim = t.getnamed('display_moviedim');
var d_movname = t.getnamed('display_moviename');
var d_movlength = t.getnamed('display_movielength');
// ask values
var mov_fps = mov.getattr('fps');
var mov_length = mov.getattr('milliseconds');
var mov_name = mov.getattr('moviefile');
var mov_size = mov.getattr('dim');
var mov_frames = Math.floor((mov_length / 1000) * mov_fps);
// show file info
d_movname.message('set', mov_name);
d_movfps.message('set','FPS:', mov_fps);
d_movdim.message('set','SIZE:', mov_size);
d_movlength.message('set', 'LENGTH: ', mov_frames, ' FRAMES');
// start internal timing function
state.message(0);
//post('\n', mov_fps);
}
function PLAY() {
init();
gett.interval = 1000;
gett.repeat();
mov.message('unique', 1);
mov.message('start');
key_32.message('set', 1);
state.message('set', 1);
if (hide == 1) {
//setcursor.message('set', 1);
//max.hidecursor();
}
}
function STOP() {
init();
mov.message('unique', 0);
mov.message('stop');
gett.cancel();
key_32.message('set', 0);
state.message('set', 0);
if (loopmode == 0) {
//max.showcursor();
//setcursor.message('set', 0);
}
}
function REWIND() {
STOP();
mov.message('frame_true', 0);
}
function position(f)
{
var getms = t.getnamed('getms');
getms.message('bang');
mov.message('position',f);
}
// -------------------------------------------------
// TIMER Functions
// -------------------------------------------------
// -------------------------------------------------
// LOOP UND BREAK FUNCTIONS
// -------------------------------------------------
var framecount = 0;
var loopmode;
function setloop(i)
{
if (i == 0) {
loopmode = 0;
//post('\n', 'Loop disabled');
}
else {
loopmode = 1;
//post('\n', 'Loop enabled');
}
return loopmode;
}
function endreached()
{
if (loopmode == 1) {
STOP();
PLAY();
}
// loop = off
else {
STOP();
//post('\n', 'FINISHED');
}
}
// -------------------------------------------------
// JS BANG FUNCTIONS
// -------------------------------------------------
var gett = new Task(getinfo,this);
// ask current position
function getinfo() {
var getms = t.getnamed('getms');
var getpos = t.getnamed('getpos');
getpos.message('bang');
getms.message('bang');
}
// -------------------------------------------------
// LOADBANG Functions
// -------------------------------------------------
function loadbang() {
//init();
}