Skip to content

Commit 9132147

Browse files
committed
Merge branch 'master' into midi
2 parents c3055d1 + fc32069 commit 9132147

File tree

9 files changed

+1026
-3
lines changed

9 files changed

+1026
-3
lines changed

src/core/b-init.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ extern const REBYTE Str_Banner[];
249249

250250
for (word++; NOT_END(word); word++, n++) {
251251
COPY_BYTES(str, Get_Word_Name(word), 32);
252+
str[31] = '\0';
252253
str[LEN_BYTES(str)-1] = '?';
253254
sym = Make_Word(str, 0);
254255
//Print("sym: %s", Get_Sym_Name(sym));
@@ -608,7 +609,7 @@ extern const REBYTE Str_Banner[];
608609
value = Get_System(SYS_CATALOG, CAT_ACTIONS);
609610
Set_Block(value, Collect_Set_Words(VAL_BLK(&Boot_Block->actions)));
610611

611-
// Create system/catalog/actions block:
612+
// Create system/catalog/nativess block:
612613
value = Get_System(SYS_CATALOG, CAT_NATIVES);
613614
Set_Block(value, Collect_Set_Words(VAL_BLK(&Boot_Block->natives)));
614615

@@ -835,21 +836,25 @@ static REBCNT Set_Option_Word(REBCHR *str, REBCNT field)
835836
if (NZ(data = OS_GET_LOCALE(0))) {
836837
val = Get_System(SYS_LOCALE, LOCALE_LANGUAGE);
837838
Set_String(val, Copy_OS_Str(data, (REBINT)LEN_STR(data)));
839+
OS_FREE(data);
838840
}
839841

840842
if (NZ(data = OS_GET_LOCALE(1))) {
841843
val = Get_System(SYS_LOCALE, LOCALE_LANGUAGE_P);
842844
Set_String(val, Copy_OS_Str(data, (REBINT)LEN_STR(data)));
845+
OS_FREE(data);
843846
}
844847

845848
if (NZ(data = OS_GET_LOCALE(2))) {
846849
val = Get_System(SYS_LOCALE, LOCALE_LOCALE);
847850
Set_String(val, Copy_OS_Str(data, (REBINT)LEN_STR(data)));
851+
OS_FREE(data);
848852
}
849853

850854
if (NZ(data = OS_GET_LOCALE(3))) {
851855
val = Get_System(SYS_LOCALE, LOCALE_LOCALE_P);
852856
Set_String(val, Copy_OS_Str(data, (REBINT)LEN_STR(data)));
857+
OS_FREE(data);
853858
}
854859
}
855860

src/core/d-crash.c

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ enum Crash_Msg_Nums {
7878

7979
// "REBOL PANIC #nnn:"
8080
COPY_BYTES(buf, Crash_Msgs[CM_ERROR], CRASH_BUF_SIZE);
81+
buf[CRASH_BUF_SIZE - 1] = '\0';
8182
APPEND_BYTES(buf, cb_cast(" #"), CRASH_BUF_SIZE);
8283
Form_Int(buf + LEN_BYTES(buf), id);
8384
APPEND_BYTES(buf, cb_cast(": "), CRASH_BUF_SIZE);
@@ -96,6 +97,8 @@ enum Crash_Msg_Nums {
9697
msg = (REBYTE*)(n >= 0 ? Crash_Msgs[n] : BOOT_STR(RS_ERROR, id - RP_STR_BASE - 1));
9798
Form_Var_Args(buf + LEN_BYTES(buf), (REBCNT)(CRASH_BUF_SIZE - 1 - LEN_BYTES(buf)), msg, args);
9899

100+
va_end(args);
101+
99102
APPEND_BYTES(buf, Crash_Msgs[CM_CONTACT], CRASH_BUF_SIZE);
100103

101104
// Convert to OS-specific char-type:

src/core/n-audio.c

+205
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
/***********************************************************************
2+
**
3+
** REBOL [R3] Language Interpreter and Run-time Environment
4+
**
5+
** Copyright 2012 REBOL Technologies
6+
** Copyright 2012-2017 Rebol Open Source Contributors
7+
** REBOL is a trademark of REBOL Technologies
8+
**
9+
** Licensed under the Apache License, Version 2.0 (the "License");
10+
** you may not use this file except in compliance with the License.
11+
** You may obtain a copy of the License at
12+
**
13+
** http://www.apache.org/licenses/LICENSE-2.0
14+
**
15+
** Unless required by applicable law or agreed to in writing, software
16+
** distributed under the License is distributed on an "AS IS" BASIS,
17+
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
** See the License for the specific language governing permissions and
19+
** limitations under the License.
20+
**
21+
************************************************************************
22+
**
23+
** Module: n-audio.c
24+
** Summary: native audio related functions
25+
** Section: natives
26+
** Author: Oldes
27+
** Notes:
28+
**
29+
***********************************************************************/
30+
31+
#include "sys-core.h"
32+
33+
34+
const REBYTE sound_name[] = "sound!"; //Used as a context handle name
35+
//const REBYTE aes_name[] = "AES-context";
36+
37+
/***********************************************************************
38+
**
39+
*/ REBNATIVE(audio)
40+
/*
41+
// audio: native [
42+
// "Audio DSL entry"
43+
// commands [block!] "Audio commands to evaluate."
44+
// ]
45+
***********************************************************************/
46+
{
47+
REBVAL *temp;
48+
REBINT ssp; // starting stack pointer
49+
50+
DS_PUSH_NONE;
51+
temp = DS_TOP;
52+
ssp = DSP;
53+
54+
REBVAL *value = VAL_BLK(D_ARG(1));
55+
REBSER *ctx;
56+
REBVAL *next;
57+
58+
REBSER *frame;
59+
REBVAL *spec;
60+
REBSER *obj;
61+
62+
for (; NOT_END(value); value++) {
63+
if (IS_SET_WORD(value)) {
64+
puts("-- found set-word?");
65+
DS_PUSH(value);
66+
} else {
67+
// Get value:
68+
if (IS_WORD(value)) {
69+
switch (VAL_WORD_CANON(value)) {
70+
case SYM_LOAD:
71+
printf("nextvaltype: %i\n", VAL_TYPE(value+1));
72+
//ctx = Make_Series(1024, (REBCNT)1, FALSE);
73+
spec = Get_System(SYS_STANDARD, STD_SOUND);
74+
if (!IS_OBJECT(spec)) Trap_Arg(spec);
75+
obj = CLONE_OBJECT(VAL_OBJ_FRAME(spec));
76+
77+
SET_HANDLE(temp, obj);
78+
VAL_HANDLE_NAME(temp) = sound_name;
79+
puts("KEY");
80+
break;
81+
case SYM_CREATE:
82+
// Build standard sound object:
83+
spec = Get_System(SYS_STANDARD, STD_SOUND);
84+
if (!IS_OBJECT(spec)) Trap_Arg(spec);
85+
obj = CLONE_OBJECT(VAL_OBJ_FRAME(spec));
86+
//SET_OBJECT(temp, VAL_OBJ_FRAME(obj));
87+
//puts("CREATE");
88+
break;
89+
case SYM_PLAY:
90+
next = value + 1;
91+
if (IS_HANDLE(next) || (IS_WORD(next) && IS_HANDLE(Get_Var(next)))) {
92+
puts("haauds handle");
93+
obj = (REBVAL*)VAL_HANDLE(next);
94+
SET_OBJECT(temp, obj);
95+
value++;
96+
}
97+
else {
98+
puts("command missing handle value");
99+
}
100+
101+
//SET_
102+
break;
103+
case SYM_NONE:
104+
SET_NONE(temp);
105+
break;
106+
case SYM_TRUE:
107+
case SYM_ON:
108+
case SYM_YES:
109+
SET_TRUE(temp);
110+
break;
111+
case SYM_FALSE:
112+
case SYM_OFF:
113+
case SYM_NO:
114+
SET_FALSE(temp);
115+
break;
116+
default:
117+
*temp = *value;
118+
VAL_SET(temp, REB_WORD);
119+
}
120+
}
121+
else if (IS_LIT_WORD(value)) {
122+
*temp = *value;
123+
VAL_SET(temp, REB_WORD);
124+
}
125+
else if (IS_LIT_PATH(value)) {
126+
*temp = *value;
127+
VAL_SET(temp, REB_PATH);
128+
}
129+
else if (VAL_TYPE(value) >= REB_NONE) { // all valid values
130+
*temp = *value;
131+
}
132+
else
133+
SET_NONE(temp);
134+
135+
// Set prior set-words:
136+
while (DSP > ssp) {
137+
Set_Var(DS_TOP, temp);
138+
DS_DROP;
139+
}
140+
}
141+
}
142+
DS_DROP; // temp
143+
#if 0
144+
REBSER *ser;
145+
REBINT index;
146+
// REBINT tail;
147+
148+
// index = (REBINT)VAL_INDEX(value);
149+
// tail = (REBINT)VAL_TAIL(value);
150+
// ser = VAL_SERIES(value);
151+
152+
REBVAL *cmds = VAL_BLK(val_commands);
153+
REBVAL *tail = VAL_BLK_TAIL(val_commands);
154+
REBINT len = VAL_BLK_LEN(val_commands);
155+
156+
printf("Audio commands: %i %i\n", len, tail - cmds);
157+
158+
while(cmds < tail) {
159+
printf("Value has type ID: %i\n", VAL_TYPE(cmds));
160+
if (IS_SET_WORD(cmds)) {
161+
//Set_Var((REBVAL*)cmds, (REBVAL*)cmds);
162+
//SET_LOGIC(cmds, TRUE);
163+
164+
//SET_TRUE(Get_Var(cmds));
165+
SET_INTEGER(Get_Var(cmds), 42);
166+
}
167+
if (IS_WORD(cmds) && VAL_WORD_CANON(cmds) == SYM_ON) {
168+
puts("ON");
169+
}
170+
cmds++;
171+
}
172+
#endif
173+
/*
174+
175+
REBVAL *ret = D_RET;
176+
REBSER *ctx;
177+
178+
if(ref_stream) {
179+
ctx = (REBSER*)VAL_HANDLE(val_ctx);
180+
181+
if (VAL_HANDLE_NAME(val_ctx) != rc4_name) {
182+
Trap0(RE_INVALID_HANDLE);
183+
}
184+
185+
REBYTE *data = VAL_BIN_AT(val_data);
186+
RC4_crypt((RC4_CTX*)ctx->data, data, data, VAL_LEN(val_data));
187+
DS_RET_VALUE(val_data);
188+
189+
} else if (ref_key) {
190+
//key defined - setup new context
191+
//making series from POOL so it will be GCed automaticaly
192+
REBSER* ctx = Make_Series(sizeof(RC4_CTX), (REBCNT)1, FALSE);
193+
194+
RC4_setup(
195+
(RC4_CTX*)ctx->data,
196+
VAL_BIN_AT(val_crypt_key),
197+
VAL_LEN(val_crypt_key)
198+
);
199+
200+
SET_HANDLE(ret, ctx);
201+
VAL_HANDLE_NAME(ret) = rc4_name;
202+
}
203+
return R_RET;*/
204+
return R_ARG1;
205+
}

src/core/p-midi.c

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/***********************************************************************
2+
**
3+
** REBOL [R3] Language Interpreter and Run-time Environment
4+
**
5+
** Copyright 2012 REBOL Technologies
6+
** Copyright 2012-2019 Rebol Open Source Developers
7+
** REBOL is a trademark of REBOL Technologies
8+
**
9+
** Licensed under the Apache License, Version 2.0 (the "License");
10+
** you may not use this file except in compliance with the License.
11+
** You may obtain a copy of the License at
12+
**
13+
** http://www.apache.org/licenses/LICENSE-2.0
14+
**
15+
** Unless required by applicable law or agreed to in writing, software
16+
** distributed under the License is distributed on an "AS IS" BASIS,
17+
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
** See the License for the specific language governing permissions and
19+
** limitations under the License.
20+
**
21+
************************************************************************
22+
**
23+
** Module: p-midi.c
24+
** Summary: MIDI port interface
25+
** Section: ports
26+
** Author: Oldes
27+
** Notes:
28+
**
29+
***********************************************************************/
30+
31+
#include "sys-core.h"
32+
33+
/***********************************************************************
34+
**
35+
*/ static int MIDI_Actor(REBVAL *ds, REBSER *port, REBCNT action)
36+
/*
37+
***********************************************************************/
38+
{
39+
REBREQ *req;
40+
REBINT result;
41+
REBVAL *arg;
42+
REBCNT refs; // refinement argument flags
43+
REBINT len;
44+
REBSER *ser;
45+
46+
printf("MIDI_Actor action: %i\n", action);
47+
48+
Validate_Port(port, action);
49+
50+
arg = D_ARG(2);
51+
52+
req = Use_Port_State(port, RDI_MIDI, sizeof(REBREQ));
53+
54+
switch (action) {
55+
56+
case A_READ:
57+
// This device is opened on the READ:
58+
#ifdef unused
59+
if (!IS_OPEN(req)) {
60+
if (OS_DO_DEVICE(req, RDC_OPEN)) Trap_Port(RE_CANNOT_OPEN, port, req->error);
61+
}
62+
// Issue the read request:
63+
CLR_FLAG(req->flags, RRF_WIDE); // allow byte or wide chars
64+
result = OS_DO_DEVICE(req, RDC_READ);
65+
if (result < 0) Trap_Port(RE_READ_ERROR, port, req->error);
66+
67+
// Copy and set the string result:
68+
arg = OFV(port, STD_PORT_DATA);
69+
70+
// If wide, correct length:
71+
len = req->actual;
72+
if (GET_FLAG(req->flags, RRF_WIDE)) len /= sizeof(REBUNI);
73+
74+
// Copy the string (convert to latin-8 if it fits):
75+
Set_String(arg, Copy_OS_Str(req->data, len));
76+
77+
OS_FREE(req->data); // release the copy buffer
78+
req->data = 0;
79+
#endif
80+
*D_RET = *arg;
81+
return R_RET;
82+
83+
case A_WRITE:
84+
85+
break;
86+
87+
case A_OPEN:
88+
if (OS_DO_DEVICE(req, RDC_OPEN)) Trap_Port(RE_CANNOT_OPEN, port, req->error);
89+
break;
90+
91+
case A_CLOSE:
92+
OS_DO_DEVICE(req, RDC_CLOSE);
93+
break;
94+
95+
case A_QUERY:
96+
OS_DO_DEVICE(req, RDC_QUERY);
97+
break;
98+
99+
case A_OPENQ:
100+
if (IS_OPEN(req)) return R_TRUE;
101+
return R_FALSE;
102+
103+
default:
104+
Trap_Action(REB_PORT, action);
105+
}
106+
107+
return R_ARG1; // port
108+
}
109+
110+
111+
/***********************************************************************
112+
**
113+
*/ void Init_MIDI_Scheme(void)
114+
/*
115+
***********************************************************************/
116+
{
117+
Register_Scheme(SYM_MIDI, 0, MIDI_Actor);
118+
}

0 commit comments

Comments
 (0)