Mercurial > hg > dmlib
comparison minijss/jloadjss.c @ 1208:fa758951720f
Remove some code duplication.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 05 Mar 2015 21:24:12 +0200 |
parents | 5d20c80df290 |
children | 6b48bad13399 |
comparison
equal
deleted
inserted
replaced
1207:59b5821b5cf9 | 1208:fa758951720f |
---|---|
24 #define JSGETBYTE(XV) \ | 24 #define JSGETBYTE(XV) \ |
25 if (!dmf_read_byte(inFile, XV)) \ | 25 if (!dmf_read_byte(inFile, XV)) \ |
26 return DMERR_OUT_OF_DATA | 26 return DMERR_OUT_OF_DATA |
27 | 27 |
28 | 28 |
29 #if defined(JM_SUP_PATMODE_1) || defined(JM_SUP_PATMODE_3) | 29 static int jssDoGetConvertedNote(DMResource *inFile, JSSNote *pnote, Uint8 note) |
30 static int jssGetConvertedNote(DMResource *inFile, JSSNote *pnote) | |
31 { | 30 { |
32 Uint8 tmp; | 31 Uint8 tmp; |
33 | 32 |
34 JSGETBYTE(&tmp); | 33 if (note == 127) |
35 | |
36 if (tmp == 127) | |
37 pnote->note = jsetNoteOff; | 34 pnote->note = jsetNoteOff; |
38 else if (tmp == 0) | 35 else |
36 if (note == 0) | |
39 pnote->note = jsetNotSet; | 37 pnote->note = jsetNotSet; |
40 else | 38 else |
41 pnote->note = tmp - 1; | 39 pnote->note = note - 1; |
42 | 40 |
43 JSGETBYTE(&tmp); | 41 JSGETBYTE(&tmp); |
44 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet; | 42 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet; |
45 | 43 |
46 JSGETBYTE(&tmp); | 44 JSGETBYTE(&tmp); |
52 JSGETBYTE(&tmp); | 50 JSGETBYTE(&tmp); |
53 pnote->param = (tmp == 0 && pnote->effect == jsetNotSet) ? jsetNotSet : tmp; | 51 pnote->param = (tmp == 0 && pnote->effect == jsetNotSet) ? jsetNotSet : tmp; |
54 | 52 |
55 return DMERR_OK; | 53 return DMERR_OK; |
56 } | 54 } |
57 #endif | 55 |
56 | |
57 static inline int jssGetConvertedNote(DMResource *inFile, JSSNote *pnote) | |
58 { | |
59 Uint8 tmp; | |
60 JSGETBYTE(&tmp); | |
61 return jssDoGetConvertedNote(inFile, pnote, tmp); | |
62 } | |
58 | 63 |
59 | 64 |
60 #if defined(JM_SUP_PATMODE_2) || defined(JM_SUP_PATMODE_4) | 65 #if defined(JM_SUP_PATMODE_2) || defined(JM_SUP_PATMODE_4) |
61 static int jssGetCompressedNote(DMResource *inFile, JSSNote *pnote) | 66 static int jssGetCompressedNote(DMResource *inFile, JSSNote *pnote) |
62 { | 67 { |
99 pnote->param = tmp; | 104 pnote->param = tmp; |
100 } | 105 } |
101 } | 106 } |
102 else | 107 else |
103 { | 108 { |
104 tmp = packb; | 109 int ret; |
105 | 110 if ((ret = jssDoGetConvertedNote(inFile, pnote, packb)) != DMERR_OK) |
106 if (tmp == 127) | 111 return ret; |
107 pnote->note = jsetNoteOff; | |
108 else | |
109 if (tmp == 0) | |
110 pnote->note = jsetNotSet; | |
111 else | |
112 pnote->note = tmp - 1; | |
113 | |
114 JSGETBYTE(&tmp); | |
115 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet; | |
116 | |
117 JSGETBYTE(&tmp); | |
118 pnote->volume = (tmp > 0) ? tmp - 1 : jsetNotSet; | |
119 | |
120 JSGETBYTE(&tmp); | |
121 pnote->effect = (tmp > 0) ? tmp - 1 : jsetNotSet; | |
122 | |
123 JSGETBYTE(&tmp); | |
124 pnote->param = (tmp == 0 && pnote->effect == jsetNotSet) ? jsetNotSet : tmp; | |
125 } | 112 } |
126 | 113 |
127 return DMERR_OK; | 114 return DMERR_OK; |
128 } | 115 } |
129 #endif | 116 #endif |