noobs 0.0.31 → 0.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/noobs.node +0 -0
- package/index.d.ts +18 -5
- package/package.json +1 -1
- package/src/main.cpp +52 -10
- package/src/obs_interface.cpp +31 -7
- package/src/obs_interface.h +2 -1
package/dist/noobs.node
CHANGED
|
Binary file
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
type Signal = {
|
|
2
|
-
id: string;
|
|
3
|
-
code: number;
|
|
1
|
+
export type Signal = {
|
|
2
|
+
id: string; // Signal identifier, e.g. "stop"
|
|
3
|
+
code: number; // 0 for success, other values for errors
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export type SceneItemPosition = {
|
|
7
|
+
x: number; // X position in pixels
|
|
8
|
+
y: number; // Y position in pixels
|
|
9
|
+
scaleX: number; // X scaling factor
|
|
10
|
+
scaleY: number; // Y scaling factor
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type SourceDimensions = {
|
|
14
|
+
height: number; // Height in pixels, before scaling
|
|
15
|
+
width: number; // Width in pixels, before scaling
|
|
4
16
|
}
|
|
5
17
|
|
|
6
18
|
interface Noobs {
|
|
@@ -18,7 +30,8 @@ interface Noobs {
|
|
|
18
30
|
StopRecording(): void;
|
|
19
31
|
GetLastRecording(): string;
|
|
20
32
|
|
|
21
|
-
|
|
33
|
+
GetSourcePos(src: string): SceneItemPosition & SourceDimensions;
|
|
34
|
+
SetSourcePos(src: string, pos: SceneItemPosition): void;
|
|
22
35
|
|
|
23
36
|
InitPreview(hwnd: Buffer): void;
|
|
24
37
|
ShowPreview(x: number, y: number, width: number, height: number): void;
|
|
@@ -26,4 +39,4 @@ interface Noobs {
|
|
|
26
39
|
}
|
|
27
40
|
|
|
28
41
|
declare const noobs: Noobs;
|
|
29
|
-
export
|
|
42
|
+
export default noobs;
|
package/package.json
CHANGED
package/src/main.cpp
CHANGED
|
@@ -157,22 +157,63 @@ Napi::Value ObsHidePreview(const Napi::CallbackInfo& info) {
|
|
|
157
157
|
return info.Env().Undefined();
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
Napi::Value
|
|
160
|
+
Napi::Value ObsGetSourcePos(const Napi::CallbackInfo& info) {
|
|
161
161
|
if (!obs) {
|
|
162
162
|
blog(LOG_ERROR, "ObsUpdateSource called but obs is not initialized");
|
|
163
163
|
throw std::runtime_error("Obs not initialized");
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
bool valid = info.Length() ==
|
|
167
|
-
info[0].IsNumber() && // X position (px)
|
|
168
|
-
info[1].IsNumber() && // Y position (px)
|
|
169
|
-
info[2].IsNumber(); // Scale (multiplier)
|
|
166
|
+
bool valid = info.Length() == 1 && info[0].IsString();
|
|
170
167
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
168
|
+
if (!valid) {
|
|
169
|
+
Napi::TypeError::New(info.Env(), "Invalid arguments passed to ObsGetSourcePos").ThrowAsJavaScriptException();
|
|
170
|
+
return info.Env().Undefined();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
std::string name = info[0].As<Napi::String>().Utf8Value();
|
|
174
|
+
|
|
175
|
+
vec2 pos; vec2 size; vec2 scale;
|
|
176
|
+
obs->getSourcePos(name, &pos, &size, &scale);
|
|
177
|
+
|
|
178
|
+
Napi::Object result = Napi::Object::New(info.Env());
|
|
179
|
+
result.Set("x", Napi::Number::New(info.Env(), pos.x));
|
|
180
|
+
result.Set("y", Napi::Number::New(info.Env(), pos.y));
|
|
181
|
+
result.Set("width", Napi::Number::New(info.Env(), size.x));
|
|
182
|
+
result.Set("height", Napi::Number::New(info.Env(), size.y));
|
|
183
|
+
result.Set("scaleX", Napi::Number::New(info.Env(), scale.x));
|
|
184
|
+
result.Set("scaleY", Napi::Number::New(info.Env(), scale.y));
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
Napi::Value ObsSetSourcePos(const Napi::CallbackInfo& info) {
|
|
189
|
+
if (!obs) {
|
|
190
|
+
blog(LOG_ERROR, "ObsUpdateSource called but obs is not initialized");
|
|
191
|
+
throw std::runtime_error("Obs not initialized");
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
bool valid = info.Length() == 6 &&
|
|
195
|
+
info[0].IsString() && // Source name
|
|
196
|
+
info[1].IsNumber() && // X position (px)
|
|
197
|
+
info[2].IsNumber() && // Y position (px)
|
|
198
|
+
info[3].IsNumber() && // Scale factor (X)
|
|
199
|
+
info[4].IsNumber(); // Scale factor (Y)
|
|
200
|
+
|
|
201
|
+
if (!valid) {
|
|
202
|
+
Napi::TypeError::New(info.Env(), "Invalid arguments passed to ObsSetSourcePos").ThrowAsJavaScriptException();
|
|
203
|
+
return info.Env().Undefined();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
std::string name = info[0].As<Napi::String>().Utf8Value();
|
|
207
|
+
|
|
208
|
+
float x = info[1].As<Napi::Number>().FloatValue();
|
|
209
|
+
float y = info[2].As<Napi::Number>().FloatValue();
|
|
210
|
+
vec2 pos = { x, y };
|
|
211
|
+
|
|
212
|
+
float scaleX = info[3].As<Napi::Number>().FloatValue();
|
|
213
|
+
float scaleY = info[4].As<Napi::Number>().FloatValue();
|
|
214
|
+
vec2 scale = { scaleX, scaleY };
|
|
174
215
|
|
|
175
|
-
obs->
|
|
216
|
+
obs->setSourcePos(name, &pos, &scale);
|
|
176
217
|
return info.Env().Undefined();
|
|
177
218
|
}
|
|
178
219
|
|
|
@@ -185,7 +226,8 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
|
185
226
|
exports.Set("StopRecording", Napi::Function::New(env, ObsStopRecording));
|
|
186
227
|
exports.Set("GetLastRecording", Napi::Function::New(env, ObsGetLastRecording));
|
|
187
228
|
|
|
188
|
-
exports.Set("
|
|
229
|
+
exports.Set("GetSourcePos", Napi::Function::New(env, ObsGetSourcePos));
|
|
230
|
+
exports.Set("SetSourcePos", Napi::Function::New(env, ObsSetSourcePos));
|
|
189
231
|
|
|
190
232
|
exports.Set("InitPreview", Napi::Function::New(env, ObsInitPreview));
|
|
191
233
|
exports.Set("ShowPreview", Napi::Function::New(env, ObsShowPreview));
|
package/src/obs_interface.cpp
CHANGED
|
@@ -613,18 +613,42 @@ std::string ObsInterface::getLastRecording() {
|
|
|
613
613
|
return path;
|
|
614
614
|
}
|
|
615
615
|
|
|
616
|
-
void ObsInterface::
|
|
617
|
-
|
|
618
|
-
|
|
616
|
+
void ObsInterface::getSourcePos(std::string name, vec2* pos, vec2* size, vec2* scale)
|
|
617
|
+
{
|
|
618
|
+
blog(LOG_INFO, "ObsInterface::getSourcePos called");
|
|
619
|
+
|
|
620
|
+
obs_source_t *src = obs_get_source_by_name(name.c_str());
|
|
621
|
+
obs_sceneitem_t *item = obs_scene_find_source(scene, name.c_str());
|
|
622
|
+
|
|
623
|
+
if (!src) {
|
|
624
|
+
blog(LOG_ERROR, "Did not find source for video ");
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
619
627
|
|
|
620
628
|
if (!item) {
|
|
621
629
|
blog(LOG_ERROR, "Did not find scene item for video source");
|
|
622
630
|
return;
|
|
623
631
|
}
|
|
624
632
|
|
|
625
|
-
|
|
626
|
-
|
|
633
|
+
obs_sceneitem_get_pos(item, pos);
|
|
634
|
+
obs_sceneitem_get_scale(item, scale);
|
|
635
|
+
|
|
636
|
+
// Pre-scaled sizes.
|
|
637
|
+
size->x = obs_source_get_width(src);
|
|
638
|
+
size->y = obs_source_get_height(src);
|
|
639
|
+
|
|
640
|
+
blog(LOG_INFO, "ObsInterface::getSourcePos exited");
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
void ObsInterface::setSourcePos(std::string name, vec2* pos, vec2* scale) {
|
|
644
|
+
blog(LOG_INFO, "ObsInterface::moveSource called");
|
|
645
|
+
obs_sceneitem_t *item = obs_scene_find_source(scene, name.c_str());
|
|
646
|
+
|
|
647
|
+
if (!item) {
|
|
648
|
+
blog(LOG_ERROR, "Did not find scene item for video source");
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
627
651
|
|
|
628
|
-
|
|
629
|
-
obs_sceneitem_set_scale(item,
|
|
652
|
+
obs_sceneitem_set_pos(item, pos);
|
|
653
|
+
obs_sceneitem_set_scale(item, scale);
|
|
630
654
|
}
|
package/src/obs_interface.h
CHANGED
|
@@ -24,7 +24,8 @@ class ObsInterface {
|
|
|
24
24
|
void stopRecording();
|
|
25
25
|
std::string getLastRecording();
|
|
26
26
|
|
|
27
|
-
void
|
|
27
|
+
void getSourcePos(std::string name, vec2* pos, vec2* size, vec2* scale); // Size is returned to allow clients to calculate scale.
|
|
28
|
+
void setSourcePos(std::string name, vec2* pos, vec2* scale); // Size does not get set here because it's set by the source itself.
|
|
28
29
|
|
|
29
30
|
void initPreview(HWND parent); // Must call this before showPreview to setup resources.
|
|
30
31
|
void showPreview(int x, int y, int width, int height); // Also used for moving and resizing.
|