@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.
@@ -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