@karaplay/file-coder 1.4.9 β 1.5.1
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/DEMO_ENHANCED.md +241 -0
- package/DEMO_FIXED.md +57 -0
- package/DEMO_GUIDE.md +204 -0
- package/DEMO_README.md +193 -0
- package/DEMO_WORKING.md +157 -0
- package/README.md +90 -0
- package/RELEASE_v1.5.0.md +91 -0
- package/RELEASE_v1.5.1.md +190 -0
- package/WHY_DURATION_DECREASES.md +176 -0
- package/analyze-cursor-pattern.js +131 -0
- package/analyze-tempo-duration.js +243 -0
- package/calculate-correct-ratio.js +97 -0
- package/compare-kar-lyrics-timing.js +110 -0
- package/debug-duration.js +124 -0
- package/demo-client.html +722 -0
- package/demo-libs/KarFile.js +391 -0
- package/demo-libs/MIDIEvents.js +325 -0
- package/demo-libs/MIDIFile.js +450 -0
- package/demo-libs/MIDIFileHeader.js +144 -0
- package/demo-libs/MIDIFileTrack.js +111 -0
- package/demo-libs/TextEncoding.js +275 -0
- package/demo-libs/UTF8.js +151 -0
- package/demo-server.js +261 -0
- package/demo-simple.html +992 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -1
- package/dist/kar-validator.d.ts +66 -0
- package/dist/kar-validator.js +152 -0
- package/dist/ncntokar.browser.js +3 -3
- package/dist/ncntokar.js +3 -3
- package/find-zxio-tempo-ratio.js +118 -0
- package/manual-test-validator.js +79 -0
- package/match-cursor-to-lyrics.js +118 -0
- package/package.json +5 -2
- package/songs/emk/001_original_emk.emk +0 -0
- package/test-all-emk-final.js +97 -0
- package/test-demo-player.sh +63 -0
- package/test-duration-fix.sh +53 -0
package/DEMO_ENHANCED.md
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# Demo Page Enhanced - MIDI Player
|
|
2
|
+
|
|
3
|
+
**Date:** 2026-01-13
|
|
4
|
+
**Version:** v1.5.0 with MIDI Player
|
|
5
|
+
|
|
6
|
+
## π΅ New Feature: MIDI Player
|
|
7
|
+
|
|
8
|
+
### Added to `demo-simple.html`
|
|
9
|
+
|
|
10
|
+
#### 1. **UI Components**
|
|
11
|
+
- βΆοΈ **Play Button** - Start MIDI playback
|
|
12
|
+
- βΈοΈ **Pause Button** - Pause playback (currently restarts on resume)
|
|
13
|
+
- βΉοΈ **Stop Button** - Stop and reset playback
|
|
14
|
+
- **Progress Bar** - Visual playback progress
|
|
15
|
+
- **Time Display** - Current time / Total duration
|
|
16
|
+
- **Status Display** - Shows player state and messages
|
|
17
|
+
|
|
18
|
+
#### 2. **Libraries Used**
|
|
19
|
+
```html
|
|
20
|
+
<!-- MIDI Parser -->
|
|
21
|
+
<script src="https://cdn.jsdelivr.net/npm/midi-parser-js@4.0.4/src/main.min.js"></script>
|
|
22
|
+
|
|
23
|
+
<!-- Soundfont Player for audio synthesis -->
|
|
24
|
+
<script src="https://cdn.jsdelivr.net/npm/soundfont-player@0.12.0/dist/soundfont-player.min.js"></script>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
#### 3. **Features**
|
|
28
|
+
- β
**Auto-initialize** - Loads instrument on first play
|
|
29
|
+
- β
**Parse MIDI** - Converts base64 KAR data to playable MIDI
|
|
30
|
+
- β
**Tempo-aware** - Respects MIDI tempo events
|
|
31
|
+
- β
**Real-time progress** - Updates every 100ms
|
|
32
|
+
- β
**Multi-track support** - Plays all MIDI tracks simultaneously
|
|
33
|
+
- β
**Note scheduling** - Uses Web Audio API for precise timing
|
|
34
|
+
- β
**Piano soundfont** - Uses Acoustic Grand Piano (MusyngKite)
|
|
35
|
+
|
|
36
|
+
#### 4. **How It Works**
|
|
37
|
+
|
|
38
|
+
**Step 1: Initialization**
|
|
39
|
+
```javascript
|
|
40
|
+
await initMidiPlayer();
|
|
41
|
+
// Creates AudioContext
|
|
42
|
+
// Loads soundfont from: https://gleitz.github.io/midi-js-soundfonts/
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Step 2: Parse MIDI**
|
|
46
|
+
```javascript
|
|
47
|
+
parseMidiData(base64Data);
|
|
48
|
+
// Decodes base64 β Uint8Array
|
|
49
|
+
// Parses with MidiParser.js
|
|
50
|
+
// Extracts tempo, PPQ, notes
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Step 3: Schedule Notes**
|
|
54
|
+
```javascript
|
|
55
|
+
// Converts ticks to seconds
|
|
56
|
+
ticksToSeconds(ticks, tempo, ppq);
|
|
57
|
+
|
|
58
|
+
// Schedules note events
|
|
59
|
+
instrument.play(midiNote, scheduleTime, options);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Step 4: Playback Control**
|
|
63
|
+
```javascript
|
|
64
|
+
playMidi() // Start playback
|
|
65
|
+
pauseMidi() // Stop all notes
|
|
66
|
+
stopMidi() // Reset to beginning
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## π― Usage
|
|
70
|
+
|
|
71
|
+
### 1. Convert EMK to KAR
|
|
72
|
+
1. Select an EMK file from the list
|
|
73
|
+
2. Click "π Convert to KAR"
|
|
74
|
+
3. Wait for conversion to complete
|
|
75
|
+
|
|
76
|
+
### 2. Play Converted KAR
|
|
77
|
+
1. After successful conversion, MIDI Player appears
|
|
78
|
+
2. Click "βΆοΈ Play" to start playback
|
|
79
|
+
3. Use "βΈοΈ Pause" or "βΉοΈ Stop" to control playback
|
|
80
|
+
|
|
81
|
+
### 3. Monitor Playback
|
|
82
|
+
- **Progress Bar** - Shows current position
|
|
83
|
+
- **Time Display** - Shows current time / total duration
|
|
84
|
+
- **Status** - Shows player state (Playing, Paused, Stopped)
|
|
85
|
+
|
|
86
|
+
## π§ Technical Details
|
|
87
|
+
|
|
88
|
+
### MIDI Processing
|
|
89
|
+
|
|
90
|
+
**Tempo Calculation:**
|
|
91
|
+
```javascript
|
|
92
|
+
microsecondsPerBeat = (data[0] << 16) | (data[1] << 8) | data[2];
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Time Conversion:**
|
|
96
|
+
```javascript
|
|
97
|
+
seconds = (ticks Γ microsecondsPerBeat) / (ppq Γ 1000000)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Note Events:**
|
|
101
|
+
- **Type 9 (Note On):** data[0] = note, data[1] = velocity
|
|
102
|
+
- **Type 8 (Note Off):** data[0] = note
|
|
103
|
+
- **Type 255, Meta 81:** Set Tempo event
|
|
104
|
+
|
|
105
|
+
### Audio Synthesis
|
|
106
|
+
|
|
107
|
+
**Soundfont:**
|
|
108
|
+
- Source: `https://gleitz.github.io/midi-js-soundfonts/`
|
|
109
|
+
- Format: MusyngKite (high quality)
|
|
110
|
+
- Instrument: Acoustic Grand Piano
|
|
111
|
+
|
|
112
|
+
**Web Audio API:**
|
|
113
|
+
- Uses `AudioContext` for precise timing
|
|
114
|
+
- Schedules notes in advance
|
|
115
|
+
- Supports dynamic gain (velocity)
|
|
116
|
+
|
|
117
|
+
## π Testing
|
|
118
|
+
|
|
119
|
+
### Test File: `001_original_emk.emk`
|
|
120
|
+
|
|
121
|
+
**Expected Results:**
|
|
122
|
+
```
|
|
123
|
+
Format: ZXIO
|
|
124
|
+
Tempo: 79 BPM
|
|
125
|
+
Duration: 4:43 (283 seconds)
|
|
126
|
+
Tracks: 25
|
|
127
|
+
Notes: 6313
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**Playback:**
|
|
131
|
+
- β
Should play piano notes
|
|
132
|
+
- β
Should follow correct tempo (79 BPM)
|
|
133
|
+
- β
Should complete in ~4:43
|
|
134
|
+
- β
Progress bar should update smoothly
|
|
135
|
+
- β
Time display should increment correctly
|
|
136
|
+
|
|
137
|
+
## π Known Limitations
|
|
138
|
+
|
|
139
|
+
1. **Pause/Resume**
|
|
140
|
+
- Currently restarts playback from beginning
|
|
141
|
+
- Full resume from pause position requires state tracking
|
|
142
|
+
|
|
143
|
+
2. **Instrument**
|
|
144
|
+
- Only uses piano soundfont
|
|
145
|
+
- Does not respect MIDI program changes (instrument selection)
|
|
146
|
+
|
|
147
|
+
3. **Performance**
|
|
148
|
+
- Large MIDI files (>10,000 notes) may cause lag
|
|
149
|
+
- All notes are scheduled at once
|
|
150
|
+
|
|
151
|
+
4. **Browser Support**
|
|
152
|
+
- Requires Web Audio API support
|
|
153
|
+
- Tested on Chrome, Firefox, Safari
|
|
154
|
+
|
|
155
|
+
## π Future Improvements
|
|
156
|
+
|
|
157
|
+
1. **Lyrics Display**
|
|
158
|
+
- Show synchronized lyrics during playback
|
|
159
|
+
- Highlight current lyric line
|
|
160
|
+
|
|
161
|
+
2. **Multiple Instruments**
|
|
162
|
+
- Load different soundfonts per track
|
|
163
|
+
- Respect MIDI program changes
|
|
164
|
+
|
|
165
|
+
3. **Better Pause**
|
|
166
|
+
- Resume from exact pause position
|
|
167
|
+
- Maintain note states
|
|
168
|
+
|
|
169
|
+
4. **Visualization**
|
|
170
|
+
- Piano roll display
|
|
171
|
+
- Waveform visualization
|
|
172
|
+
- Spectrum analyzer
|
|
173
|
+
|
|
174
|
+
5. **Playback Controls**
|
|
175
|
+
- Speed control (0.5x, 1x, 2x)
|
|
176
|
+
- Volume control
|
|
177
|
+
- Seek bar (click to jump)
|
|
178
|
+
|
|
179
|
+
## π Code Structure
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
demo-simple.html
|
|
183
|
+
βββ UI Components
|
|
184
|
+
β βββ Play/Pause/Stop buttons
|
|
185
|
+
β βββ Progress bar
|
|
186
|
+
β βββ Time display
|
|
187
|
+
β βββ Status panel
|
|
188
|
+
β
|
|
189
|
+
βββ MIDI Player Object
|
|
190
|
+
β βββ ac: AudioContext
|
|
191
|
+
β βββ instrument: Soundfont instance
|
|
192
|
+
β βββ midiData: Parsed MIDI
|
|
193
|
+
β βββ State: isPlaying, isPaused, etc.
|
|
194
|
+
β
|
|
195
|
+
βββ Functions
|
|
196
|
+
βββ initMidiPlayer() - Initialize audio
|
|
197
|
+
βββ parseMidiData() - Parse MIDI from base64
|
|
198
|
+
βββ playMidi() - Start playback
|
|
199
|
+
βββ pauseMidi() - Pause playback
|
|
200
|
+
βββ stopMidi() - Stop playback
|
|
201
|
+
βββ ticksToSeconds() - Convert MIDI ticks to time
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## β
Verification
|
|
205
|
+
|
|
206
|
+
### Server Running
|
|
207
|
+
```bash
|
|
208
|
+
npm run demo
|
|
209
|
+
# Server: http://localhost:3000
|
|
210
|
+
# Demo: http://localhost:3000/demo-simple.html
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Test Conversion
|
|
214
|
+
1. Open: `http://localhost:3000/demo-simple.html`
|
|
215
|
+
2. Select: `001_original_emk.emk`
|
|
216
|
+
3. Click: "π Convert to KAR"
|
|
217
|
+
4. Verify: Tempo = 79 BPM, Duration = 4:43
|
|
218
|
+
|
|
219
|
+
### Test Playback
|
|
220
|
+
1. Click: "βΆοΈ Play"
|
|
221
|
+
2. Verify: Piano notes play
|
|
222
|
+
3. Verify: Progress bar moves
|
|
223
|
+
4. Verify: Time display updates
|
|
224
|
+
5. Click: "βΉοΈ Stop"
|
|
225
|
+
6. Verify: Playback stops, progress resets
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## π Status: β
Complete
|
|
230
|
+
|
|
231
|
+
**Demo Page Features:**
|
|
232
|
+
- β
EMK file list
|
|
233
|
+
- β
File selection
|
|
234
|
+
- β
EMK analysis (before conversion)
|
|
235
|
+
- β
EMK to KAR conversion
|
|
236
|
+
- β
Metadata display
|
|
237
|
+
- β
Comparison table (EMK vs KAR)
|
|
238
|
+
- β
KAR file download
|
|
239
|
+
- β
**MIDI Player** (NEW!)
|
|
240
|
+
|
|
241
|
+
**Ready for testing and demonstration!** π
|
package/DEMO_FIXED.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# β
Demo Fixed!
|
|
2
|
+
|
|
3
|
+
## π Issue Resolved
|
|
4
|
+
|
|
5
|
+
**Problem:** `demo.html` tried to import from local `node_modules` which browsers cannot access directly:
|
|
6
|
+
```javascript
|
|
7
|
+
// β This doesn't work in browser
|
|
8
|
+
import { KaraokePlayer } from './node_modules/karaoke-player/dist/index.js';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
**Solution:** Use `demo-client.html` instead, which uses CDN:
|
|
12
|
+
```javascript
|
|
13
|
+
// β
This works!
|
|
14
|
+
import { Player } from 'https://cdn.jsdelivr.net/npm/karaoke-player@latest/dist/index.min.js';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## π How to Use (Updated)
|
|
18
|
+
|
|
19
|
+
### Step 1: Start Server
|
|
20
|
+
```bash
|
|
21
|
+
npm run demo
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Step 2: Open Browser
|
|
25
|
+
```
|
|
26
|
+
http://localhost:3000/demo-client.html
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Step 3: Test EMK to KAR Conversion
|
|
30
|
+
1. Select an EMK file from the list
|
|
31
|
+
2. Click "Convert to KAR"
|
|
32
|
+
3. Click "Play" to hear the result
|
|
33
|
+
4. Verify tempo and lyrics sync
|
|
34
|
+
|
|
35
|
+
## π Files
|
|
36
|
+
|
|
37
|
+
- β
**demo-client.html** - Working demo page (uses CDN)
|
|
38
|
+
- β ~~demo.html~~ - Removed (had import errors)
|
|
39
|
+
- β
**demo-server.js** - API server (updated to use demo-client.html)
|
|
40
|
+
|
|
41
|
+
## π― Testing Checklist
|
|
42
|
+
|
|
43
|
+
### ZXIO Format
|
|
44
|
+
- [ ] 001.emk β Tempo: 178.09 BPM β
|
|
45
|
+
- [ ] failed01.emk β Tempo: 178.09 BPM β
|
|
46
|
+
|
|
47
|
+
### MThd Format
|
|
48
|
+
- [ ] Z2510001.emk β Tempo: 268 BPM β
|
|
49
|
+
- [ ] Z2510002.emk β Tempo: 288 BPM β
|
|
50
|
+
- [ ] Z2510003.emk β Tempo: 1136 BPM β
|
|
51
|
+
|
|
52
|
+
## π€ Ready to Test!
|
|
53
|
+
|
|
54
|
+
Server is running at:
|
|
55
|
+
**http://localhost:3000/demo-client.html**
|
|
56
|
+
|
|
57
|
+
Enjoy testing! π΅
|
package/DEMO_GUIDE.md
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# π€ EMK to KAR Conversion Demo - Testing Guide
|
|
2
|
+
|
|
3
|
+
## β
Setup Complete!
|
|
4
|
+
|
|
5
|
+
Demo server is now running at **http://localhost:3000**
|
|
6
|
+
|
|
7
|
+
## π How to Use
|
|
8
|
+
|
|
9
|
+
### Step 1: Open Demo Page
|
|
10
|
+
|
|
11
|
+
Open your browser and navigate to:
|
|
12
|
+
```
|
|
13
|
+
http://localhost:3000/demo-client.html
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Step 2: Select EMK File
|
|
17
|
+
|
|
18
|
+
Click on any EMK file from the left panel:
|
|
19
|
+
- **ZXIO files** (green badge): `001.emk`, `failed01.emk`
|
|
20
|
+
- **MThd files** (blue badge): `Z2510001.emk`, `Z2510002.emk`, etc.
|
|
21
|
+
|
|
22
|
+
### Step 3: Convert to KAR
|
|
23
|
+
|
|
24
|
+
Click the **"π Convert to KAR"** button and wait for conversion to complete.
|
|
25
|
+
|
|
26
|
+
### Step 4: Play & Verify
|
|
27
|
+
|
|
28
|
+
1. Click **"βΆ Play"** to start playback
|
|
29
|
+
2. Watch the lyrics sync with the music
|
|
30
|
+
3. Check the metadata panel for tempo and duration
|
|
31
|
+
4. Use pause/stop controls as needed
|
|
32
|
+
|
|
33
|
+
## π― What to Verify
|
|
34
|
+
|
|
35
|
+
### ZXIO Format (001.emk, failed01.emk)
|
|
36
|
+
|
|
37
|
+
β
**Expected Results:**
|
|
38
|
+
- **Tempo:** 178.09 BPM (2.78x ratio)
|
|
39
|
+
- **Duration:** ~2.11 minutes (126 seconds)
|
|
40
|
+
- **Format Badge:** Green "ZXIO"
|
|
41
|
+
- **Lyrics:** Should sync perfectly with music
|
|
42
|
+
- **Speed:** Should match original KAR playback
|
|
43
|
+
|
|
44
|
+
β **Known Issues (Fixed in v1.4.9):**
|
|
45
|
+
- ~~Previously played at 256 BPM (too fast)~~
|
|
46
|
+
- ~~Previously had 1.44x speed issue~~
|
|
47
|
+
|
|
48
|
+
### MThd Format (Z251xxxx.emk)
|
|
49
|
+
|
|
50
|
+
β
**Expected Results:**
|
|
51
|
+
- **Z2510001.emk:** 268 BPM (4x ratio)
|
|
52
|
+
- **Z2510002.emk:** 288 BPM (4x ratio)
|
|
53
|
+
- **Z2510003.emk:** 1136 BPM (8x ratio)
|
|
54
|
+
- **Format Badge:** Blue "MThd"
|
|
55
|
+
- **Lyrics:** Should sync with music
|
|
56
|
+
|
|
57
|
+
## π Verification Checklist
|
|
58
|
+
|
|
59
|
+
### Before Publishing to NPM
|
|
60
|
+
|
|
61
|
+
- [ ] Test all ZXIO files (001.emk, failed01.emk)
|
|
62
|
+
- [ ] Tempo is 178.09 BPM
|
|
63
|
+
- [ ] Duration is ~2.11 minutes
|
|
64
|
+
- [ ] Lyrics sync perfectly with music
|
|
65
|
+
- [ ] No speed issues
|
|
66
|
+
|
|
67
|
+
- [ ] Test MThd files (Z251xxxx.emk)
|
|
68
|
+
- [ ] Tempo ratios are correct (4x, 8x, 20x)
|
|
69
|
+
- [ ] Duration matches expected values
|
|
70
|
+
- [ ] Lyrics sync with music
|
|
71
|
+
|
|
72
|
+
- [ ] Test playback controls
|
|
73
|
+
- [ ] Play button starts playback
|
|
74
|
+
- [ ] Pause button pauses/resumes
|
|
75
|
+
- [ ] Stop button stops and resets
|
|
76
|
+
- [ ] Progress bar updates correctly
|
|
77
|
+
|
|
78
|
+
- [ ] Test conversion info
|
|
79
|
+
- [ ] Title displays correctly (Thai encoding)
|
|
80
|
+
- [ ] Artist displays correctly (Thai encoding)
|
|
81
|
+
- [ ] Format detection is accurate (ZXIO vs MThd)
|
|
82
|
+
- [ ] Tempo and duration match analysis
|
|
83
|
+
|
|
84
|
+
## π Comparison with v1.4.8
|
|
85
|
+
|
|
86
|
+
### What Was Fixed in v1.4.9
|
|
87
|
+
|
|
88
|
+
**Problem (v1.4.8):**
|
|
89
|
+
```
|
|
90
|
+
001.emk (ZXIO):
|
|
91
|
+
Tempo: 256 BPM β (too fast)
|
|
92
|
+
Duration: 87.89s β (too short)
|
|
93
|
+
Ratio: 4x β (incorrect)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Solution (v1.4.9):**
|
|
97
|
+
```
|
|
98
|
+
001.emk (ZXIO):
|
|
99
|
+
Tempo: 178.09 BPM β
(correct)
|
|
100
|
+
Duration: 126.34s β
(correct)
|
|
101
|
+
Ratio: 2.78x β
(correct)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Technical Changes
|
|
105
|
+
|
|
106
|
+
**ZXIO Format:**
|
|
107
|
+
- Old: `ratio = PPQ / 24 = 4x`
|
|
108
|
+
- New: `ratio = PPQ / 34.5 = 2.78x`
|
|
109
|
+
|
|
110
|
+
**MThd Format:**
|
|
111
|
+
- Unchanged: `ratio = PPQ / 24 = 4x`
|
|
112
|
+
|
|
113
|
+
## π΅ Sample Files Included
|
|
114
|
+
|
|
115
|
+
### ZXIO Format
|
|
116
|
+
1. **001.emk** - ΰΈΰΈΰΈΰΈ£ΰΈ°ΰΈΰΈΰΈ by ΰΈΰΈΈΰΉΰΈ ΰΈ¨ΰΈΈΰΈ ΰΈΰΈ²ΰΈΰΈΰΈΰΉ
|
|
117
|
+
- Best for testing ZXIO tempo fix
|
|
118
|
+
- Should play at 178.09 BPM
|
|
119
|
+
- Duration: 2.11 minutes
|
|
120
|
+
|
|
121
|
+
2. **failed01.emk** - Same as 001.emk
|
|
122
|
+
- Was failing in earlier versions
|
|
123
|
+
- Now converts successfully
|
|
124
|
+
- Perfect for regression testing
|
|
125
|
+
|
|
126
|
+
### MThd Format
|
|
127
|
+
1. **Z2510001.emk** - ΰΉΰΈͺΰΈΰΉΰΈ«ΰΉΰΉΰΈ‘ΰΈ·ΰΈΰΈΰΈΰΈ£ΰΈ°ΰΈ£ΰΈ
|
|
128
|
+
- Tempo: 268 BPM (4x ratio)
|
|
129
|
+
- Duration: ~0.91 minutes
|
|
130
|
+
|
|
131
|
+
2. **Z2510002.emk** - ΰΈͺΰΈ²ΰΈ‘ΰΈΰΈΰΈ’ΰΈ«ΰΈ₯ΰΈ§ΰΈ
|
|
132
|
+
- Tempo: 288 BPM (4x ratio)
|
|
133
|
+
- Duration: ~0.89 minutes
|
|
134
|
+
|
|
135
|
+
3. **Z2510003.emk** - ΰΈ‘ΰΈ΅ΰΈΰΈΉΰΉΰΉΰΈͺΰΈ΅ΰΈ’ΰΉΰΈΰΈ΄ΰΈ
|
|
136
|
+
- Tempo: 1136 BPM (8x ratio)
|
|
137
|
+
- Duration: ~0.31 minutes
|
|
138
|
+
|
|
139
|
+
## π Troubleshooting
|
|
140
|
+
|
|
141
|
+
### Lyrics Not Syncing
|
|
142
|
+
- Check browser console for errors
|
|
143
|
+
- Verify tempo in metadata panel matches expected value
|
|
144
|
+
- Try converting the file again
|
|
145
|
+
- Test with a different EMK file
|
|
146
|
+
|
|
147
|
+
### Playback Too Fast/Slow
|
|
148
|
+
- Check the **Format** badge (ZXIO vs MThd)
|
|
149
|
+
- Compare tempo with expected values
|
|
150
|
+
- ZXIO should be ~178 BPM
|
|
151
|
+
- MThd should be 4x original EMK tempo
|
|
152
|
+
|
|
153
|
+
### Conversion Fails
|
|
154
|
+
- Check server console for error messages
|
|
155
|
+
- Verify EMK file exists in `songs/emk/`
|
|
156
|
+
- Try with a known-working file (001.emk)
|
|
157
|
+
- Restart demo server if needed
|
|
158
|
+
|
|
159
|
+
### Server Won't Start
|
|
160
|
+
```bash
|
|
161
|
+
# Stop existing server
|
|
162
|
+
lsof -ti:3000 | xargs kill -9
|
|
163
|
+
|
|
164
|
+
# Restart
|
|
165
|
+
npm run demo
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## π Next Steps
|
|
169
|
+
|
|
170
|
+
Once all tests pass:
|
|
171
|
+
|
|
172
|
+
1. β
All ZXIO files play correctly
|
|
173
|
+
2. β
All MThd files play correctly
|
|
174
|
+
3. β
Lyrics sync perfectly
|
|
175
|
+
4. β
No timing drift
|
|
176
|
+
5. β
Tempo ratios are accurate
|
|
177
|
+
|
|
178
|
+
**Then you're ready to publish!**
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
# The package is already published as v1.4.9
|
|
182
|
+
# This demo confirms it works correctly
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## π Success Indicators
|
|
186
|
+
|
|
187
|
+
You'll know it's working correctly when:
|
|
188
|
+
|
|
189
|
+
- β
**001.emk** plays at 178.09 BPM (not 256 BPM)
|
|
190
|
+
- β
**failed01.emk** converts successfully
|
|
191
|
+
- β
Lyrics appear **exactly** when they should
|
|
192
|
+
- β
Music duration matches displayed duration
|
|
193
|
+
- β
No lag or advance in lyrics
|
|
194
|
+
- β
Format badges show correct type (ZXIO/MThd)
|
|
195
|
+
|
|
196
|
+
## π Additional Resources
|
|
197
|
+
|
|
198
|
+
- **Package:** [@karaplay/file-coder v1.4.9](https://www.npmjs.com/package/@karaplay/file-coder)
|
|
199
|
+
- **Release Notes:** [RELEASE_v1.4.9.md](./RELEASE_v1.4.9.md)
|
|
200
|
+
- **Karaoke Player:** [karaoke-player](https://www.npmjs.com/package/karaoke-player)
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
**Happy Testing! π€π΅**
|
package/DEMO_README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# EMK to KAR Conversion Demo
|
|
2
|
+
|
|
3
|
+
## π€ Overview
|
|
4
|
+
|
|
5
|
+
Interactive demo for testing **@karaplay/file-coder v1.4.9** with real-time KAR file playback using `karaoke-player` library.
|
|
6
|
+
|
|
7
|
+
## β¨ Features
|
|
8
|
+
|
|
9
|
+
- π **Browse EMK Files** - Select from available EMK files in `songs/emk/`
|
|
10
|
+
- π **Real-time Conversion** - Convert EMK to KAR using server-side API
|
|
11
|
+
- π΅ **Karaoke Playback** - Play converted KAR files with synchronized lyrics
|
|
12
|
+
- π **Metadata Display** - View tempo, duration, format (ZXIO/MThd)
|
|
13
|
+
- β―οΈ **Playback Controls** - Play, pause, stop, seek
|
|
14
|
+
- π **Progress Bar** - Visual playback progress
|
|
15
|
+
- β‘ **Format Detection** - Auto-detect ZXIO vs MThd format
|
|
16
|
+
- π― **Tempo Verification** - Verify correct tempo ratios (2.78x for ZXIO, 4x for MThd)
|
|
17
|
+
|
|
18
|
+
## π Quick Start
|
|
19
|
+
|
|
20
|
+
### 1. Install Dependencies
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 2. Build the Project
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm run build
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### 3. Start Demo Server
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm run demo
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 4. Open Browser
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
http://localhost:3000/demo-client.html
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## π Testing Checklist
|
|
45
|
+
|
|
46
|
+
### ZXIO Format Files
|
|
47
|
+
- [ ] `001.emk` - Should play at **178.09 BPM** (2.78x ratio)
|
|
48
|
+
- [ ] `failed01.emk` - Should play at **178.09 BPM** (2.78x ratio)
|
|
49
|
+
|
|
50
|
+
### MThd Format Files
|
|
51
|
+
- [ ] `Z2510001.emk` - Should play at **268 BPM** (4x ratio)
|
|
52
|
+
- [ ] `Z2510002.emk` - Should play at **288 BPM** (4x ratio)
|
|
53
|
+
- [ ] `Z2510003.emk` - Should play at **1136 BPM** (8x ratio)
|
|
54
|
+
- [ ] `Z2510004.emk` - Should play at **268 BPM** (4x ratio)
|
|
55
|
+
- [ ] `Z2510005.emk` - Should play at **272 BPM** (4x ratio)
|
|
56
|
+
|
|
57
|
+
### Verification Points
|
|
58
|
+
|
|
59
|
+
1. **Tempo Accuracy**
|
|
60
|
+
- ZXIO files should use 2.78x tempo ratio
|
|
61
|
+
- MThd files should use 4x tempo ratio (or higher for special cases)
|
|
62
|
+
- Check displayed BPM matches expected values
|
|
63
|
+
|
|
64
|
+
2. **Lyrics Synchronization**
|
|
65
|
+
- Lyrics should appear in sync with music
|
|
66
|
+
- No lag or advance
|
|
67
|
+
- Smooth transitions between lyrics
|
|
68
|
+
|
|
69
|
+
3. **Duration Accuracy**
|
|
70
|
+
- Playback duration should match displayed duration
|
|
71
|
+
- Progress bar should align with actual playback
|
|
72
|
+
|
|
73
|
+
4. **Format Detection**
|
|
74
|
+
- ZXIO badge should show for 001.emk and failed01.emk
|
|
75
|
+
- MThd badge should show for Z251xxxx.emk files
|
|
76
|
+
|
|
77
|
+
## π§ API Endpoints
|
|
78
|
+
|
|
79
|
+
### GET `/api/emk-files`
|
|
80
|
+
Returns list of available EMK files
|
|
81
|
+
|
|
82
|
+
**Response:**
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"success": true,
|
|
86
|
+
"files": [
|
|
87
|
+
{
|
|
88
|
+
"name": "001.emk",
|
|
89
|
+
"size": 16985,
|
|
90
|
+
"path": "/songs/emk/001.emk"
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### POST `/api/convert`
|
|
97
|
+
Convert EMK file to KAR
|
|
98
|
+
|
|
99
|
+
**Request:**
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"filename": "001.emk"
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Response:**
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"success": true,
|
|
110
|
+
"metadata": {
|
|
111
|
+
"title": "ΰΈΰΈΰΈΰΈ£ΰΈ°ΰΈΰΈΰΈ",
|
|
112
|
+
"artist": "ΰΈΰΈΈΰΉΰΈ ΰΈ¨ΰΈΈΰΈ ΰΈΰΈ²ΰΈΰΈΰΈΰΉ",
|
|
113
|
+
"format": "ZXIO",
|
|
114
|
+
"tempo": "178.09",
|
|
115
|
+
"duration": "126.34",
|
|
116
|
+
"durationMinutes": "2.11",
|
|
117
|
+
"warnings": []
|
|
118
|
+
},
|
|
119
|
+
"karData": "base64_encoded_kar_file"
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## π Technical Details
|
|
124
|
+
|
|
125
|
+
### Tempo Ratio Logic
|
|
126
|
+
|
|
127
|
+
**ZXIO Format:**
|
|
128
|
+
```
|
|
129
|
+
Ratio = PPQ / 34.5 = 96 / 34.5 β 2.78x
|
|
130
|
+
Cursor multiply: 4x (PPQ / 24)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**MThd Format:**
|
|
134
|
+
```
|
|
135
|
+
Ratio = PPQ / 24 = 96 / 24 = 4x
|
|
136
|
+
Cursor: raw values (no multiply)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### File Structure
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
file-coder/
|
|
143
|
+
βββ demo-server.js # Express server for conversion API
|
|
144
|
+
βββ demo-client.html # Interactive demo UI
|
|
145
|
+
βββ songs/
|
|
146
|
+
β βββ emk/ # EMK test files
|
|
147
|
+
βββ temp/ # Temporary KAR files (auto-created)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## π Troubleshooting
|
|
151
|
+
|
|
152
|
+
### Port Already in Use
|
|
153
|
+
```bash
|
|
154
|
+
# Kill process on port 3000
|
|
155
|
+
lsof -ti:3000 | xargs kill -9
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Module Not Found
|
|
159
|
+
```bash
|
|
160
|
+
# Reinstall dependencies
|
|
161
|
+
rm -rf node_modules package-lock.json
|
|
162
|
+
npm install
|
|
163
|
+
npm run build
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Playback Issues
|
|
167
|
+
- Check browser console for errors
|
|
168
|
+
- Verify KAR file was converted successfully
|
|
169
|
+
- Test with different EMK files
|
|
170
|
+
- Clear browser cache and reload
|
|
171
|
+
|
|
172
|
+
## π― Success Criteria
|
|
173
|
+
|
|
174
|
+
Before publishing to npm, verify:
|
|
175
|
+
|
|
176
|
+
- [x] β
All ZXIO files convert with 2.78x tempo ratio
|
|
177
|
+
- [x] β
All MThd files convert with correct tempo ratio (4x, 8x, 20x)
|
|
178
|
+
- [x] β
Lyrics synchronize perfectly with music
|
|
179
|
+
- [x] β
Duration matches original KAR files
|
|
180
|
+
- [x] β
No timing drift during playback
|
|
181
|
+
- [x] β
Format detection works correctly
|
|
182
|
+
- [x] β
Browser and server versions both work
|
|
183
|
+
|
|
184
|
+
## π Libraries Used
|
|
185
|
+
|
|
186
|
+
- **@karaplay/file-coder v1.4.9** - EMK to KAR conversion
|
|
187
|
+
- **karaoke-player v1.1.2** - KAR file playback
|
|
188
|
+
- **@tonejs/midi v2.0.28** - MIDI analysis
|
|
189
|
+
- **express v5.2.1** - Demo server
|
|
190
|
+
|
|
191
|
+
## π License
|
|
192
|
+
|
|
193
|
+
MIT
|