Хакатон/Пишем музыку в Scratch/Midi-CSV generator

Материал из Letopisi.Ru — «Время вернуться домой»
Перейти к: навигация, поиск
Исходный проект https://scratch.mit.edu/projects/102685408
дополнительная информация - https://music.stackexchange.com/questions/24893/how-to-decode-this-csv-from-a-midi-file - как читаются csv файлы, перекодированные из midi
http://flashmusicgames.com/midi/index.html

Данные выглядят следующим образом:

   2, 0, MIDI_port, 0
   2, 0, Title_t, "Bass Synt"
   2, 3072, Note_on_c, 1, 26, 96
   2, 3072, Note_on_c, 1, 38, 86
   2, 3220, Note_on_c, 1, 38, 0
   2, 3220, Note_on_c, 1, 26, 0
   2, 3648, Note_on_c, 1, 26, 97
   2, 3648, Note_on_c, 1, 38, 96
   2, 3788, Note_on_c, 1, 38, 0
   2, 3788, Note_on_c, 1, 26, 0


Содержание

 [убрать

Stage

когдащелкнутпозадатьloadзначение0перейтивx:0y:0установитьэффектяркостьвзначение0задатьturbo modeзначениеfalseпоказатьсяповторятьпоканеturbomode=truedetectturbo сменитькостюмнаcostume4создатьклонсебя самогоперейтивx:-60y:-30повторить2следующийкостюмсоздатьклонсебя самогоустановитьxв162спрятатьсяопределитьdetectturboперезапуститьтаймерповторить10сменитькостюмнакостюм#задатьturbo modeзначениетаймер<0.1когдаяполучуdelete screen clonesудалитьклонкогдаяполучуapple midiперейтивx:0y:0сменитькостюмнаcostume7перейтиназадна999слоевпоказатьсясоздатьклонсебя самогоспрятатьсякогдаяполучуplay songспрятатьсяперейтивx:0y:0сменитькостюмнаcostume6перейтиназадна999слоевпоказатьсясоздатьклонсебя самогоспрятатьсякогдащелкнутпосменитькостюмнаcostume1ждать0.5секундповторятьпоканеturbomode=trueсменитькостюмнаcostume2ждать1секундсменитькостюмнаcostume3ждать0.25секундсменитькостюмнаcostume1ждать1секундкогдаяполучуloadсменитькостюмнаcostume5перейтивx:0y:0показатьсякогдаяначинаюкакклонустановитьэффектяркостьвзначение0есликостюм#=5иликостюм#=6,товсегдаесликасаетсяуказатель мышки ?,тоустановитьэффектяркостьвзначение-30еслимышканажата?,тоустановитьэффектяркостьвзначение-70есликостюм#=5,топередатьimportиначеесликостюм#=6,топередатьexamplesпередатьdelete screen clonesиначеустановитьэффектяркостьвзначение0иначе

 ?

Midi Player

defineSplit#OnEvery/tolistsetito1setproxtorepeatlengthof#ifletteriof#=/thenaddproxtolistsetproxtoelsesetproxtojoinproxletteriof#changeiby1defineRenderframe:framepenupdeleteallofFrameDatadeleteallofFrameSplititemframeofFrames OnEvery]toFrame setlto1repeatuntill>lengthofFrame SplititemlofFrame OnEvery/toFrameData changelby1setlto1repeatuntill>lengthofFrameData iflines=falsethenpenupgotox:itemlofFrameData *size-size*0.7+xy:iteml+1ofFrameData *size-size*0.7+ysetlinestoiteml+2ofFrameData pendownchangelby3defineFindletter#incharssetito1Getcaseofletter1of# ifcase=lowerthenrepeatuntilitemiofchars =joinletter1of#2changeiby1ifi>lengthofchars thensetito97stopthis scriptelserepeatuntilitemiofchars =letter1of#changeiby1ifi>lengthofchars thensetito97stopthis scriptifi<10thensetitojoin0idefineGetcaseof#switchcostumetoCase Checkerswitchcostumetoletter1of#ifnotcostume#=1thensetcasetoupperelsesetcasetolowerdefineTypeTextatx:Xy:Ythickness:thicknesssize:sizespacing:spacingReset setsizetosizesetpensizetothickness+boldsetpencolortocolorEncodeText setxtoXsetytoYdeleteallofImputsetcto1repeatlengthofCodedText/2addjoinlettercofCodedTextletterc+1ofCodedTexttoImputchangecby2setcto1repeatuntilc>lengthofImput penupifitemcofImput =07thenCustomimput:itemc+1ofImput  setpensizetothickness+boldchangecby2Renderframe:itemcofImput  changecby1changexbythickness+bold+size*12*spacingifx>237oritemcofImput =96thensetxto-230changeyby-25ifitemcofImput =96thendeletecofImputify<-180thenwait2.5secsclearsetxto-230setyto120changexbythickness+bold+size*12*spacingpenupdefineEncodetextsetCodedTexttosetcto1repeatuntilc>lengthoftextFindletterlettercoftextinchars setCodedTexttojoinCodedTextichangecby1defineCustomimput:imputifimput=77thenifbold=0thenBold:not elseBold: elseifimput=21thensetpencolortoelseifimput=68thensetpencolortoelseifimput=23thensetpencolortoelseifimput=70thensetpencolortoelseifimput=19thensetpencolortoelseifimput=66thensetpencolortoelseifimput=67thensetpencolortoelseifimput=20thensetpencolortoelseifimput=18thensetpencolortoelseifimput=26thensetpencolortoelseifimput=69thensetpencolortoelseifimput=22thensetpencolortoelseifimput=71thensetpencolortoelseifimput=24thensetpencolortoelseifimput=25thensetpencolortoelseifimput=17thensetpencolortoelsedefineResetsetpencolortoBold: defineBold:bold?ifbold?thensetboldto4elsesetboldto0whenIstartasaclonesetbrightnesseffectto0foreveriftouchingmouse-pointer ?andnotcostume#=41thensetbrightnesseffectto-30ifmousedown?thenifcostume#=40thensetbrightnesseffectto-70waituntilnotmousedown?iftimer=0thenbroadcastplay songsetpauseto0elseifpause=0thenbroadcastplay songelseifpause=1thensetpauseto0elseifcostume#=41thensetbrightnesseffectto-70waituntilnotmousedown?ifactiontrack=trackthensetaction trackto0elsesetaction tracktotrackelseifcostume#=42thensetbrightnesseffectto-70waituntilnotmousedown?ifitemtrackofmuted =0thenreplaceitemtrackofmutedwith1replaceitemtrackofsingleswith0elsereplaceitemtrackofmutedwith0elseifcostume#=43thensetbrightnesseffectto-70waituntilnotmousedown?ifitemtrackofsingles =0thenreplaceitemtrackofsingleswith1replaceitemtrackofmutedwith0elsereplaceitemtrackofsingleswith0elseifcostume#=44thensetbrightnesseffectto-70setaction tracktotrackbroadcaststop settingsandwaitbroadcastchannel settingsandwaitwaituntilnotmousedown?elseifcostume#=45orcostume#=46thensetbrightnesseffectto-70waituntilnotmousedown?ifcostume#=45thensetpauseto1switchcostumetocostume6elsebroadcastreset timerswitchcostumetocostume8elseelseifcostume#=42anditemtrackofmuted =1thensetbrightnesseffectto-30elseifcostume#=43anditemtrackofsingles =1thensetbrightnesseffectto-30elseifcostume#=46andpause=0thenswitchcostumetocostume8setbrightnesseffectto0elsesetbrightnesseffectto0whenIreceivedisplaysetplaying?to1settrackto1settext yto162broadcastdelete clonesshowclearsetsizeto100 %repeattracksifitemtrackofdrummed channels =falsethenTypejoinjoin&aitemtrack+tracks*2ofchnl var join (joinitemtrack+tracksofchnl var )atx:-155y:textythickness:2size:0.75spacing:0.8 elseTypejoinjoin&aitemtrack+tracks*2ofchnl var  (Percussion)atx:-147y:textythickness:2size:0.75spacing:0.8 Typejoin&aTracktrackatx:192-lengthoftrack-1*202-194y:textythickness:2size:0.75spacing:0.8 setpencolortogotox:-240y:texty-4pendowngotox:240y:texty-4penupgotox:-235y:textyswitchcostumetocostume2createcloneofmyselfgotox:-215y:textyswitchcostumetocostume5createcloneofmyselfgotox:-195y:textyswitchcostumetocostume3createcloneofmyselfgotox:-175y:textyswitchcostumetocostume4createcloneofmyselfchangetrackby1changetext yby-20setsizeto200 %gotox:190y:-175switchcostumetocostume1createcloneofmyselfgotox:215y:-175switchcostumetocostume8createcloneofmyselfhidewhenIreceivedelete clonesdeletethisclone

Tune generator

определитьloadnotesдобавитьэлементbar*2+bar+1изnotes кthis bar notesдобавитьэлементbar*2+bar+2изnotes кthis bar notesдобавитьэлементbar*2+bar+3изnotes кthis bar notesопределитьdeletestring1off[thisbarnotes]задатьiзначение0повторятьпоканеi>длинаспискаthis bar notes изменитьiна1Splitслитьэлементiизthis bar notes и/OnEvery/tohigh/low еслиhigh/lowсодержитstring1 ?,тозадатьlзначениеiзадатьiзначение0повторятьпоканеэлементiизhigh/low =string1изменитьiна1удалитьiизhigh/lowзадатьiзначение1задатьnew stringзначениеэлементiизhigh/low повторитьдлинаспискаhigh/low -1задатьnew stringзначениеслитьnewstringислить/иэлементiизhigh/low изменитьiна1заменитьэлементlвthis bar notesнаnewstringстопэтот скриптиначеизменитьiна1определитьpickhigh/lownoteSplitслитьnoteи/OnEvery/tohigh/low задатьnoteзначениеэлементrandomизhigh/low определитьSplit#OnEvery/tolistзадатьiзначение1задатьproxзначениеудалитьвсеизlistповторитьдлина#еслибукваiв#=/,тодобавитьproxкlistзадатьproxзначениеиначезадатьproxзначениеслитьproxибукваiв#изменитьiна1когдаяполучуgenerate tunegeneratetune1 generatetune2 generatetune3 generatetune4 generatetune5 converttomidicsv определитьconverttomidicsvудалитьвсеизmidi csvудалитьвсеизtimesзадатьjзначение1повторить5задатьlзначениеэлементjизLs добавитьэлементlизwaits *1000кtimesдобавитьслитьlи, 0, Start_trackкmidi csvдобавитьслитьlислить, 0, Program_c, 0, иэлементlизinstrument ids -1кmidi csvдобавитьслитьlислить, 0, Title_t, "ислитьэлементlизtitles и"кmidi csvзадатьlзначениеэлементjизLs повторитьэлементlизrepeats задатьkзначение1повторитьдлинаспискаслитьtuneиl Splitслитьэлементkизслитьtuneиl и:OnEvery:tohigh/low добавитьслитьlислить, ислитьэлементjизtimes ислить, Note_on_c, ислитьlислить, ислитьэлемент1изhigh/low и, 100кmidi csvдобавитьслитьlислить, ислитьэлементjизtimes +элемент2изhigh/low *1000ислить, Note_off_c, ислитьlислить, ислитьэлемент1изhigh/low и, 0кmidi csvзаменитьэлементjвtimesнаэлементjизtimes +элемент2изhigh/low *1000изменитьkна1добавитьслитьlи, 0, End_trackкmidi csvизменитьjна1добавитьслитьlи, 0, End_fileкmidi csvзаменитьэлемент1вmidi csvнаэлемент1изmidi csv определитьgeneratetunetuneеслиtune=5,тоудалитьвсеизtune5добавить36:1кtune5добавить41:1кtune5добавить36:1кtune5добавить31:1кtune5иначеудалитьвсеизслитьtuneиtuneзадатьbarзначение0задатьaddзначение1повторить4удалитьвсеизthis bar notesloadnotes задатьlengthзначениеэлементrandomизlengths задатьnoteзначениеэлементrandomизthis bar notes pickhigh/lownote добавитьслитьnoteислить:иlengthкслитьtuneиtunedeletenoteoff[thisbarnotes] еслинеlength=1,тозадатьnoteзначениеэлементrandomизthis bar notes pickhigh/lownote добавитьслитьnoteислить:иlengthкслитьtuneиtunedeletenoteoff[thisbarnotes] еслиlength=0.25,тозадатьnoteзначениеэлементrandomизthis bar notes pickhigh/lownote добавитьслитьnoteислить:иlengthкслитьtuneиtunedeletenoteoff[thisbarnotes] удалитьвсеизthis bar notesloadnotes задатьnoteзначениеэлементrandomизthis bar notes pickhigh/lownote добавитьслитьnoteислить:иlengthкслитьtuneиtunedeletenoteoff[thisbarnotes] изменитьbarна1изменитьaddна1
Персональные инструменты
Инструменты