简体   繁体   中英

How can I create a "playlist" of midi files on a raspberry pi?

I am trying to create a looping playlist of midi files on a raspberry pi for a christmas light display, i have a collection of midi files and I know that i can play them indivually with the command

aplaymidi -p 14 /home/user/Music/myMidi.mid

is there a way I can create a C script that would cycle between songs and restart once all are done?

I have looked around for info on Midi files and their interactions with C but have had little luck...

Here's a quick and dirty script to loop over the lines of a text file and play the midi files inside:

#!/bin/bash

song_names=$1     #save the filename of the list of songs
while : # infinite loop
do
    while IFS="" read -r f || [ -n "$f" ]; do  # read a line, even if missing terminating line feed
        echo "Playing $f"
        aplaymidi -p 14 "$f"
    done < "$song_names"   # read from song names file
done

There's probably ways to make it more efficient (only read the file once, for example) but this should get you started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM