|
| 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 | +} |
0 commit comments