3 RCD stay check functions
4 compatible to rcdcheck.s
6 Made by Studio Breeze. 1998
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 #include "sted_screen.h"
31 #define MAX_BAR 2048 /* max size of measure is 2048 */
32 static int bar_st[TRK_NUM][MAX_BAR];
34 //struct RCD_HEAD *rcd;
35 static char *_data_adr, *_tone_adr, *_word_adr, *_gsd_adr, *_smf_adr;
37 static void request_midi_data(char *);
39 static void _start_external_player(void);
40 static void _stop_external_player(void);
41 static void _exit_external_player(int);
42 static void null_func (void) {};
43 static void null_func_char (char in_a) {};
45 /** RCD 構造体の初期化を行う コンストラクタのようなもの */
51 /* memory allocation */
54 sizeof(struct RCD_HEAD)+
62 rcd = (struct RCD_HEAD *)malloc( alloc_size );
63 _data_adr = (char *)rcd + sizeof(struct RCD_HEAD);
64 _smf_adr = _data_adr + DATA_ADR_SIZE;
65 _tone_adr = _smf_adr + SMF_ADR_SIZE;
66 _word_adr = _tone_adr + TONE_ADR_SIZE;
67 _gsd_adr = _word_adr + WORD_ADR_SIZE;
79 rcd->version[0] = '3';
80 rcd->version[1] = '.';
81 rcd->version[2] = '0';
82 rcd->version[3] = '1';
92 rcd->data_adr = _data_adr;
93 rcd->tone_adr = _tone_adr;
94 rcd->word_adr = _word_adr;
95 rcd->gsd_adr = _gsd_adr;
96 rcd->smf_adr = _smf_adr;
98 rcd->init = null_func; /* RCD initialize ? */
99 rcd->setup = null_func; /* RCD setup routine ? */
100 rcd->begin = _start_external_player; /* start playing RCP data */
101 rcd->end = _stop_external_player; /* stop playing RCP data */
103 rcd->md_put = put_midi_data;
104 rcd->md_get = get_midi_data;
105 rcd->md_put2 = null_func_char;
106 rcd->mix_out = request_midi_data;
119 rcd->filename[0] = 0;
120 rcd->tonename[0] = 0;
124 rcd->bufcap = DATA_ADR_SIZE;
127 rcd->MIDI_req[0] = 0;
129 for( i=0;i<TRK_NUM;i++ ) {
137 void rcd_open_device( void ) {
138 open_midi_device( midi_port_name );
143 _start_external_player(void)
145 if ( STed_InitMeasureConversion() !=0 ) return;
147 start_player((unsigned char *)_data_adr, rcd->totalcount);
151 _stop_external_player(void)
157 _exit_external_player(int in_sig)
159 close_player(in_sig);
163 request_midi_data(char *in_p)
167 int add_set(int, int*);
168 int step_cluc2(int, int, int);
172 STed_InitMeasureConversion() {
178 for( i=0;i<TRK_NUM;i++ ) {
185 measure = (int *)malloc(sizeof(int)*MAX_BAR);
186 for ( i=0 ; i<TRK_NUM ; i++ ) {
187 m=add_set( i, measure );
188 for ( j=0 ; j<m ; j++ ) {
189 bar_st[i][j] = step_cluc2( i, 0, measure[j] );
198 /* converts from total step to measure & relative step */
199 static int stp_ad( int tr, int meas, int step );
201 STed_MeasureConversion( int tr ) {
204 int c=rcd->stepcount;
206 if ( rcd->bar[tr]>=0 || rcd->step[tr]>=0 ) return 0;
210 if ( bar_st[tr][i]>c ) break;
211 if ( bar_st[tr][i]<0 ) i=MAX_BAR;
216 if ( i==MAX_BAR-1 ) { /* measures ended */
223 rcd->step[tr] = stp_ad(tr, i, c-bar_st[tr][i]);
230 stp_ad( int t, int measure, int step ) {
236 unsigned char *bp=trk[t];
238 measure+=(poft&0xffff);
239 if (( poft&0xffff)==0 ) measure++;
242 po = meas_add(measure);
249 if(a==0xf7){po+=4;goto redis;}