a ‹flK@sFddlZddlZddlmZddlZddlZ ddl Z ddl Z ddl Z ddl Z ddlZddlZddlmZddlmZddlmZddlZddlmZddlTeejrdndZd Zee Z!d d Z"d d Z#ddZ$dgddZ%ddZ&ddZ'ddZ(ddZ)ddZ*dd Z+gd!Z,gd"Z-e.Z/e0d#e0d$e0d%e0d&e0d'e1e"d(Z2e2de2dfZ2e"d)Z3e4e2e3ej5d(d*e6d+e2de2dd,Z7ej8d)d-e6d+e3de3dd,Z9Wdn1s0Ye0d.e10ej:d/d0d1d,Z;eje?d7Ze1.e@ejAe,d8d9d:ZBe18ejCd;dd?ZDejAdd@gdAdd:ZEWdn1s0Yej8dBdCdDZFeBjGe$eBeFdEWdn1s80Ye@ZeHdFZIejd?ZDeHdFZIWdn1s00Ye@\ejzplot_rhythm..rblackrArZNote)colorslabelnoneZRest) edgecolor facecolorr]r^r%g?greyz--)xr\Z linestyleFg0@g?g333333?z 16th NoteszRhythm Patternz!samples/diy_examples/rhythm_plot_z.png)rLZsubplotslistr5 enumerateZscatterZaxvlineZgridZset_xlimZset_ylimZ set_xticksZ set_yticksZ set_xlabel set_titlerOclose)Z rhythm_strr^figaxrhythmrcr>rVrrr plot_rhythmzs, &(        rkcCs(t|dkr|ddS|ddSdS)NrSrT)lenljust)r]rrradjust_rhythm_strings  rncCsJ|dddd}tjdd|Dtd}|tgd}t||S)NrSrTcSsg|]}|dkrdndqS)rTrrr)rUcharrrrrWrXz*rhythm_string_to_array..)dtype)rr$rrqrr$rrqrr$rrqrr$r)rmr.arrayintprint)r]arrrrrrhythm_string_to_arrays rvcCs(t||d|d\}}}t|}|||fS)Nr)r;r')r@rQ)r9r:r' midi_output audio_outputrpiano_roll_imagerrrgenerate_from_examplesrzc  Cstd|t|dttt|dtt|dtt|dtt|dg} ||||g} tj| tjddddf| tjddddfgdd} t| } | d} | } t|  } d| vrg}t t | D]"}t | |}t |}| |qtj|dd}| |ddtjf}t|}tj|dkdd}| |||<tj|tjddddf|tjddddfgdd} t| } tj| | | gdd}t||dd \}}}t|}|||fS) Nz )rSrr)axisrrRZdiy)r;)rttyper. concatenater0CHORD_DICTIONARYnewaxiscircular_extend ones_liker5rlrnrvappend zeros_likeallr@rQ)m1_chordm2_chordm3_chordm4_chord m1_rhythm m2_rhythm m3_rhythm m4_rhythmr: test_chd_rollrhythmschd_rollZ real_chd_rollZ melody_rollZ rhythm_fullr>rjZ onset_rollZ sustain_rollZ no_onset_posr=rwrxrryrrr generate_diys: :       :r)r#rrr)rRZ1010101010101010Z1011101010111010Z1111101010111010Z1010001010101010z#
Symbolic Music Generation with Interactive Textural Guidance
ar### This is the demo page of the paper under review: Symbolic Music Generation with Interactive Textural Guidance. Here we present some of the generated results using our method. At the bottom of this page, we offer an interface for you to generate new samples on your own! z-## Accompaniment Generation for a MockingbirdamDuring a recent hike through the mountains, we encountered a mockingbird whose song carried through the air with a melody so graceful and pure. After recording a video, we took this delicate tune and repeated it four times, transforming it into a four-measure melody. Our model then crafted an accompaniment to complement this bird's song. Below, you can hear the result: the melody played on a flute, with the piano providing the accompaniment. Feel free to download both the MIDI and WAV files to explore the music yourself.z1### Video of the bird, 4-measure melody and chordzsamples/bird/bird_video.mp4z!samples/bird/melody_and_chord.jpgzA video of the birdrA)valuer^scalezMusic Sheet of Melody and Chordz### Generated Accompanimentz#samples/bird/bird_accompaniment.wavzGenerated Accompaniment, wavz#samples/bird/bird_accompaniment.midzGenerated Accompaniment, midz9## Try it on your own! a## Currently this space is running on CPU, on average, it takes roughly 15 seconds to generate a 4-measure music piece. However, if other users are generating music at the same time, you may enter a queue, which could slow down the process significantly. If that happens, feel free to refresh the page to check how many jobs are currently in the queue. We appreciate your patience and understanding during busy times! z'### Select an example to generate musicz Use ExampleszSelect an exampler#)choicesr^rFZz Select Tempor+)stepr^rNozUse Rhythm Controlrz#melody, chord, and rhythm condition)r^)fninputsoutputsZGeneratezDownload MIDI FilezGenerated MusiczGenerated Piano RollzUse Customized Chordzq## You can try to generate music pieces using customized chord by selecting the chord and rhythm for each measurez2## The default value is a famous chord progressionuw## You’re welcome to mix and match different chord and rhythm combinations to your heart’s content! But, a little warning—if your choices are a bit... shall we say, unconventional, the result might sound just as funky! After all, the model faithfully follows your musical directions, so if things get weird, that might be expected. 😏zC:majorzMeasure 1 chord)rrr^rzG:majorzMeasure 2 chordza:minorzMeasure 3 chordzF:majorzMeasure 4 chordr$TzMeasure 1 rhythm)rrZallow_custom_valuer^rzMeasure 2 rhythmzMeasure 3 rhythmzMeasure 4 rhythmz,samples/diy_examples/rhythm_plot_default.pngzmeasure 1 rhythm)rr^zmeasure 2 rhythmzmeasure 3 rhythmzmeasure 4 rhythmrqr%__main__)rrr)]ZgradiogrZ pretty_midimatplotlib.pyplotpyplotrLr4r.Z soundfilerr r sysr6osr1r<rZmodel.model_sdfrZmodel.sampler_sdfrpickleZtrain.train_paramsrZgeneration.gen_utilsr"r is_availabler,rdrkeysZ chord_listrrrr@rQrkrnrvrzrZ prompt_listZ rhythm_listZBlocksdemoMarkdownRowZbird_video_shapeZbird_sheet_image_shapertVideorsZ bird_videoImageZbird_sheet_imageAudioZ bird_audioFileZ bird_midiZTabsZTabItemZColumnZDropdownZprompt_selectorZSliderZ tempo_sliderr'Zcondition_musescorechangeButtonZgenerate_buttonrwrxZpiano_roll_outputZclickrrrrrrrrZm1_rhythm_plotZm2_rhythm_plotZm3_rhythm_plotZm4_rhythm_plotState__name__launchrrrrs        1( )        $D  0  '     40     f    2 8 :  *