Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

music.tsx 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. import abcjs from 'abcjs'
  2. import { useEffect, useRef } from 'react'
  3. import 'abcjs/abcjs-audio.css'
  4. const MarkdownMusic = ({ children }: { children: React.ReactNode }) => {
  5. const containerRef = useRef<HTMLDivElement>(null)
  6. const controlsRef = useRef<HTMLDivElement>(null)
  7. useEffect(() => {
  8. if (containerRef.current && controlsRef.current) {
  9. if (typeof children === 'string') {
  10. const visualObjs = abcjs.renderAbc(containerRef.current, children)
  11. const synthControl = new abcjs.synth.SynthController()
  12. synthControl.load(controlsRef.current, {}, { displayPlay: true })
  13. const synth = new abcjs.synth.CreateSynth()
  14. const visualObj = visualObjs[0]
  15. synth.init({ visualObj }).then(() => {
  16. synthControl.setTune(visualObj, false)
  17. })
  18. containerRef.current.style.overflow = 'auto'
  19. }
  20. }
  21. }, [children])
  22. return (
  23. <div style={{ minHeight: '350px', minWidth: '100%', overflow: 'auto' }}>
  24. <div ref={containerRef} />
  25. <div
  26. ref={controlsRef}
  27. />
  28. </div>
  29. )
  30. }
  31. MarkdownMusic.displayName = 'MarkdownMusic'
  32. export default MarkdownMusic