File size: 10,572 Bytes
08bdfee
a0fcd39
d2d01a3
b384007
 
 
 
 
 
 
d2d01a3
b384007
d2f89e9
08bdfee
 
 
 
 
 
 
 
 
 
d2d01a3
b384007
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0fcd39
b384007
a0fcd39
 
 
b384007
a0fcd39
b384007
a0fcd39
 
 
b384007
a0fcd39
 
b384007
a0fcd39
b384007
 
a0fcd39
b384007
a0fcd39
 
b384007
 
 
d2d01a3
b384007
 
 
 
 
 
 
 
 
d2d01a3
a0fcd39
 
b384007
d2d01a3
b384007
08bdfee
 
d2d01a3
08bdfee
 
 
 
 
 
 
 
d2f89e9
 
 
 
 
 
 
 
 
08bdfee
 
 
 
 
 
 
 
 
 
 
 
d2d01a3
b384007
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0fcd39
b384007
 
 
 
a0fcd39
b384007
 
 
 
a0fcd39
 
 
b384007
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0fcd39
 
b384007
 
 
a0fcd39
 
b384007
a0fcd39
b384007
 
a0fcd39
b384007
a0fcd39
 
 
b384007
a0fcd39
b384007
a0fcd39
 
 
 
 
 
b384007
 
a0fcd39
b384007
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d2d01a3
 
 
 
 
 
 
 
 
 
 
 
 
 
b384007
 
 
 
d2d01a3
b384007
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0fcd39
b384007
 
a0fcd39
b384007
 
 
 
 
 
 
 
 
a0fcd39
 
 
d2d01a3
a0fcd39
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
import React, { useState, useCallback, useEffect } from 'react'

/* Upload slots β€” hidden
const STEM_TYPES = [
  { name: 'guitar', label: 'Guitar', icon: '🎸' },
  { name: 'drums', label: 'Drums', icon: 'πŸ₯' },
  { name: 'bass', label: 'Bass', icon: '🎸' },
  { name: 'synth', label: 'Synth', icon: '🎹' },
  { name: 'click_record', label: 'Click Record', icon: '⏱️' }
]
*/

function FileUpload({ onUpload, onLoadPreset, loading, error, onClearError, cacheStatus = {} }) {
  const [presets, setPresets] = useState([])
  const [selectedPreset, setSelectedPreset] = useState('')

  useEffect(() => {
    fetch('/api/presets')
      .then(r => r.json())
      .then(data => setPresets(data.presets || []))
      .catch(() => {})
  }, [])

  /* Upload slots β€” hidden
  const [stems, setStems] = useState({
    guitar: null,
    drums: null,
    bass: null,
    synth: null,
    click_record: null
  })
  const [midiFiles, setMidiFiles] = useState([])
  const [midiDragActive, setMidiDragActive] = useState(false)

  const handleStemSelect = useCallback((stemType, file) => {
    setStems(prev => ({ ...prev, [stemType]: file }))
  }, [])

  const handleStemRemove = useCallback((stemType) => {
    setStems(prev => ({ ...prev, [stemType]: null }))
  }, [])

  const handleMidiSelect = useCallback((e) => {
    const selectedFiles = Array.from(e.target.files).filter(f =>
      f.name.toLowerCase().endsWith('.mid') || f.name.toLowerCase().endsWith('.midi')
    )
    setMidiFiles(prev => [...prev, ...selectedFiles])
  }, [])

  const handleMidiRemove = useCallback((index) => {
    setMidiFiles(prev => prev.filter((_, i) => i !== index))
  }, [])

  const handleMidiDrag = useCallback((e) => {
    e.preventDefault()
    e.stopPropagation()
    if (e.type === 'dragenter' || e.type === 'dragover') {
      setMidiDragActive(true)
    } else if (e.type === 'dragleave') {
      setMidiDragActive(false)
    }
  }, [])

  const handleMidiDrop = useCallback((e) => {
    e.preventDefault()
    e.stopPropagation()
    setMidiDragActive(false)

    const droppedFiles = Array.from(e.dataTransfer.files).filter(f =>
      f.name.toLowerCase().endsWith('.mid') || f.name.toLowerCase().endsWith('.midi')
    )
    setMidiFiles(prev => [...prev, ...droppedFiles])
  }, [])

  const handleSubmit = useCallback(async () => {
    const formData = new FormData()
    Object.entries(stems).forEach(([name, file]) => {
      if (file) formData.append(name, file)
    })
    midiFiles.forEach(file => {
      formData.append('midi', file)
    })
    await onUpload(formData)
  }, [stems, midiFiles, onUpload])

  const stemCount = Object.values(stems).filter(f => f !== null).length
  const hasFiles = stemCount > 0
  */

  return (
    <div className="glass rounded-2xl p-6 animate-fade-in max-w-4xl mx-auto">
      <h2 className="text-xl font-semibold mb-6 text-center">Load a Demo Track</h2>

      {/* Demo presets dropdown */}
      {presets.length > 0 && (
        <div className="p-4 bg-gray-800/50 rounded-xl border border-gray-600">
          <div className="flex gap-3">
            <select
              value={selectedPreset}
              onChange={(e) => setSelectedPreset(e.target.value)}
              disabled={loading}
              className="flex-1 bg-gray-800 border border-gray-600 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-primary-500"
            >
              <option value="">Select a demo...</option>
              {presets.map(p => {
                const status = cacheStatus[p]
                const label = status === 'cached'
                  ? `${p} βœ“`
                  : status === 'loading'
                    ? `${p} …`
                    : p
                return <option key={p} value={p}>{label}</option>
              })}
            </select>
            <button
              onClick={() => selectedPreset && onLoadPreset(selectedPreset)}
              disabled={loading || !selectedPreset}
              className="px-4 py-2 rounded-lg text-sm font-medium transition-all disabled:bg-gray-700 disabled:text-gray-500 disabled:cursor-not-allowed bg-gradient-to-r from-primary-600 to-accent-600 hover:from-primary-500 hover:to-accent-500"
            >
              {loading ? 'Loading...' : 'Load'}
            </button>
          </div>
        </div>
      )}

      {/* Upload slots β€” hidden
      <div className="grid grid-cols-2 gap-4 mb-6">
        {STEM_TYPES.map(({ name, label, icon }) => (
          <StemUploadCard
            key={name}
            name={name}
            label={label}
            icon={icon}
            file={stems[name]}
            onSelect={(file) => handleStemSelect(name, file)}
            onRemove={() => handleStemRemove(name)}
            disabled={loading}
          />
        ))}
      </div>

      <div
        onDragEnter={handleMidiDrag}
        onDragLeave={handleMidiDrag}
        onDragOver={handleMidiDrag}
        onDrop={handleMidiDrop}
        className={`
          mt-6 p-4 border-2 border-dashed rounded-xl transition-all
          ${midiDragActive
            ? 'border-blue-500 bg-blue-500/10'
            : 'border-gray-600'
          }
        `}
      >
        <div className="flex items-center justify-between mb-3">
          <div className="flex items-center gap-2">
            <span className="text-2xl">🎹</span>
            <span className="font-medium text-gray-300">MIDI Files (Optional)</span>
          </div>
          <label
            htmlFor="midi-input"
            className="px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg cursor-pointer transition-colors text-sm"
          >
            + Add MIDI
          </label>
          <input
            type="file"
            multiple
            accept=".mid,.midi"
            onChange={handleMidiSelect}
            className="hidden"
            id="midi-input"
            disabled={loading}
          />
        </div>

        {midiFiles.length > 0 && (
          <div className="space-y-2">
            {midiFiles.map((file, index) => (
              <div
                key={index}
                className="flex items-center justify-between bg-gray-800/50 rounded-lg px-3 py-2"
              >
                <div className="flex items-center gap-2">
                  <span className="text-sm truncate">{file.name}</span>
                  <span className="text-xs text-gray-500">
                    {(file.size / 1024).toFixed(1)} KB
                  </span>
                </div>
                <button
                  onClick={() => handleMidiRemove(index)}
                  className="text-gray-400 hover:text-red-400 transition-colors"
                  disabled={loading}
                >
                  βœ•
                </button>
              </div>
            ))}
          </div>
        )}
      </div>

      <button
        onClick={handleSubmit}
        disabled={loading || !hasFiles}
        className={`
          w-full mt-6 py-3 rounded-xl font-medium transition-all
          ${loading || !hasFiles
            ? 'bg-gray-600 cursor-not-allowed'
            : 'bg-gradient-to-r from-primary-600 to-accent-600 hover:from-primary-500 hover:to-accent-500'
          }
        `}
      >
        {loading ? (
          <span className="flex items-center justify-center gap-2">
            <span className="animate-spin">⏳</span>
            Analyzing...
          </span>
        ) : (
          `Upload ${stemCount} Stem${stemCount !== 1 ? 's' : ''}${midiFiles.length > 0 ? ` + ${midiFiles.length} MIDI` : ''}`
        )}
      </button>
      */}

      {/* Error display */}
      {error && (
        <div className="mt-4 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-red-300 text-sm flex items-center justify-between">
          <span>{error}</span>
          <button
            onClick={onClearError}
            className="text-red-400 hover:text-red-200"
          >
            βœ•
          </button>
        </div>
      )}
    </div>
  )
}

/* StemUploadCard β€” hidden
function StemUploadCard({ name, label, icon, file, onSelect, onRemove, disabled }) {
  const [dragActive, setDragActive] = React.useState(false)

  const handleFileChange = (e) => {
    const selectedFile = e.target.files[0]
    if (selectedFile && selectedFile.name.toLowerCase().endsWith('.wav')) {
      onSelect(selectedFile)
    }
  }

  const handleDrag = (e) => {
    e.preventDefault()
    e.stopPropagation()
    if (e.type === 'dragenter' || e.type === 'dragover') {
      setDragActive(true)
    } else if (e.type === 'dragleave') {
      setDragActive(false)
    }
  }

  const handleDrop = (e) => {
    e.preventDefault()
    e.stopPropagation()
    setDragActive(false)

    const droppedFile = e.dataTransfer.files[0]
    if (droppedFile && droppedFile.name.toLowerCase().endsWith('.wav')) {
      onSelect(droppedFile)
    }
  }

  return (
    <div
      onDragEnter={handleDrag}
      onDragLeave={handleDrag}
      onDragOver={handleDrag}
      onDrop={handleDrop}
      className={`
        p-4 rounded-xl border-2 transition-all
        ${file
          ? 'border-green-500 bg-green-500/10'
          : dragActive
            ? 'border-blue-500 bg-blue-500/10'
            : 'border-gray-600 hover:border-primary-500 bg-gray-800/30'
        }
      `}
    >
      <div className="flex items-center justify-between mb-3">
        <div className="flex items-center gap-2">
          <span className="text-2xl">{icon}</span>
          <span className="font-medium text-gray-300">{label}</span>
        </div>
        {file && (
          <button
            onClick={onRemove}
            className="text-gray-400 hover:text-red-400 transition-colors"
            disabled={disabled}
          >
            βœ•
          </button>
        )}
      </div>

      {file ? (
        <div className="text-sm">
          <p className="text-gray-300 truncate">{file.name}</p>
          <p className="text-gray-500 text-xs mt-1">
            {(file.size / 1024 / 1024).toFixed(1)} MB
          </p>
        </div>
      ) : (
        <label
          htmlFor={`${name}-input`}
          className="block w-full py-2 text-center bg-gray-700 hover:bg-gray-600 rounded-lg cursor-pointer transition-colors text-sm"
        >
          Select File
        </label>
      )}

      <input
        type="file"
        accept=".wav"
        onChange={handleFileChange}
        className="hidden"
        id={`${name}-input`}
        disabled={disabled}
      />
    </div>
  )
}
*/

export default FileUpload