write an example of code that produces MIDI sounds to the tune of popular urban hip-hop
- User
write an example of code that produces MIDI sounds to the tune of popular urban hip-hop
- Assistant
Here is an example of code that produces MIDI sounds to the tune of popular urban hip-hop using the Python library midiutil:
import midiutil # Set up the MIDI file tempo = 120 # beats per minute duration = 2 # seconds track = 0 channel = 0 volume = 100 program = 1 # Acoustic Piano midi_file = midiutil.MIDIFile(1) midi_file.addTempo(track, 0, tempo) # Define the notes notes = ["C5", "D5", "E5", "G5", "A5"] durations = [1, 1, 1, 1, 2] # Add the notes to the MIDI file time = 0 for note, dur in zip(notes, durations): midi_file.addProgramChange(track, channel, time, program) midi_file.addNote(track, channel, midiutil.noteNameToMidi(note), time, dur * duration, volume) time += dur * duration # Write the MIDI file to disk with open("hip_hop.mid", "wb") as output_file: midi_file.writeFile(output_file)This code creates a simple melody using the notes C5, D5, E5, G5, and A5 with different durations to create a hip-hop inspired rhythm. The midiutil library is used to create a MIDI file with the specified tempo, and the notes and durations are added to the file using the addNote method. Finally, the MIDI file is written to disk as "hip_hop.mid".
- User
thanks
- Assistant
You're welcome! Is there anything else I can help you with today?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →