123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925 |
-
- import random
- import time
- import pygame
- import sys
- import pyaudio
- import wave
- import glob
- import os
- from itertools import cycle
- from datetime import datetime
- from datetime import date
- import ast
- import random
- from pathlib import Path
- import socket
- import git
-
- #====================================
-
- State = type("State", (object,), {})
- #====================================
- class State(object):
- def __init__(self, FSM):
- self.FSM = FSM
- self.timer = 0
- self.startTime = 0
- def Enter(self):
- self.timer = 0
- self.startTime = 0
- def Execute(self):
- print('Executing')
- def Exit(self):
- print('Exiting')
-
- #====================================
-
- def play_seq(o, message):
- _id = 0
- o.clear_notes_on()
- for s in o.soundSlots:
- if s.notes[message[0]][message[1]][0] == 1:
- o.notes_on[_id] = 1
- o.soundSlots[_id].play(s.notes[message[0]][message[1]][1])
- _id += 1
- #print(o.notes_on)
- def draw_header(o):
- o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
- o.center_text(o.header_text, o.h1, o.width, 25, o.light_grey)
- o.center_text("----------------------", o.h2, o.width, 55, o.light_grey)
-
- def text_box1(o, a, b):
- w1 = 0
- w2 = (o.width / 2) - 50
- h1 = 45
- h2 = h1 + 10
- o.center_block(a, o.h2, [w1,h1,w2,h2], o.light_grey)
- o.center_block(b, o.h2, [w1,h1+10,w2,h2+25], o.light_grey)
-
- def text_box2(o, a, b):
- w1 = 0
- w2 = (o.width / 2) - 50
- h1 = 90
- h2 = h1 + 10
- o.center_block(a, o.h2, [w1,h1,w2,h2], o.light_grey)
- o.center_block(b, o.h2, [w1,h1+10,w2,h2+25], o.light_grey)
-
- def text_box3(o, a, b):
- w1 = (o.width / 2) + 40
- w2 = o.width
- h1 = 45
- h2 = h1 + 10
- o.center_block(a, o.h2, [w1,h1,w2,h2], o.light_grey)
- o.center_block(b, o.h2, [w1,h1+10,w2,h2+25], o.light_grey)
-
- def text_box4(o, a, b):
- w1 = (o.width / 2) + 40
- w2 = o.width
- h1 = 90
- h2 = h1 + 10
- o.center_block(a, o.h2, [w1,h1,w2,h2], o.light_grey)
- o.center_block(b, o.h2, [w1,h1+10,w2,h2+25], o.light_grey)
-
- def text_center(o, a, b):
- w1 = 0
- w2 = o.width
- h1 = 45
- h2 = h1 + 10
- o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
- o.center_block(a, o.h1, [w1,h1,w2,h2], o.light_grey)
- o.center_block(b, o.h1, [w1,h1+20,w2,h2+45], o.light_grey)
-
- #====================================
-
- def breakup_song_text(song):
- line1 = ""
- line2 = ""
- line3 = ""
- line4 = ""
- if len(song) < 9:
- for x in song:
- line1 += str(x) + '.'
- elif len(song) < 17:
- _iter = 0
- for x in song:
- if _iter < 8:
- line1 += str(x) + '.'
- else:
- line2 += str(x) + '.'
- _iter += 1
- elif len(song) < 25:
- _iter = 0
- for x in song:
- if _iter < 8:
- line1 += str(x) + '.'
- elif _iter < 16:
- line2 += str(x) + '.'
- else:
- line3 += str(x) + '.'
- _iter += 1
- elif len(song) < 33:
- _iter = 0
- for x in song:
- if _iter < 8:
- line1 += str(x) + '.'
- elif _iter < 16:
- line2 += str(x) + '.'
- elif _iter < 24:
- line3 += str(x) + '.'
- else:
- line4 += str(x) + '.'
- _iter += 1
- else:
- _iter = 0
- cur_id = len(song) - 1
- _iter = 0
- ns = song.copy()
- while len(ns) > 31:
- del ns[0]
- for x in ns:
- if _iter < 7:
- line1 += str(x) + '.'
- elif _iter < 15:
- line2 += str(x) + '.'
- elif _iter < 23:
- line3 += str(x) + '.'
- else:
- line4 += str(x) + '.'
- _iter += 1
- line1 = ".." + line1
- return [line1, line2, line3, line4]
-
- def draw_menu1(o):
- bpm_inc = 4
- x_size = o.width / 4
- y_size = o.height / 4
- og_x = 0
- o_x = og_x
- o_y = o.height
- text_padding = 6
- _id = 0
- while _id < 16:
-
- o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.blue)
-
- if _id == 0:
- o.center_block("Main", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 1:
- o.center_block("Note", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 2:
- o.center_block("Patt", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 3:
- o.center_block("Song", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 4:
- o.center_block("File", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 5:
- o.center_block("Util", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- # if _id == 6:
- # o.center_block("Bank-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- # if _id == 7:
- # o.center_block("Bank+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 8:
- o.center_block("Vol-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 9:
- o.center_block("Vol+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 11:
- o.center_block("", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 12:
- o.center_block("Play", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 13:
- o.center_block("Stop", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 14:
- o.center_block("BPM-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 15:
- o.center_block("BPM+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
-
-
- o_x = o_x + x_size
- _id += 1
- if _id % 4 == 0:
- o_y -= y_size
- o_x = og_x
-
-
- def draw_menu2_sample(o):
- bpm_inc = 4
- x_size = o.width / 4
- y_size = o.height / 4
- og_x = 0
- o_x = og_x
- o_y = o.height
- text_padding = 6
- _id = 0
- while _id < 16:
-
- o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.dark_grey)
-
-
- if _id == 0:
- o.center_block("Copy", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 1:
- o.center_block("Paste", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 2:
- o.center_block("Del", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 3:
- o.center_block("Load", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
-
- if _id == 4:
- o.center_block("Vol-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 5:
- o.center_block("Vol+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 6:
- o.center_block("Bank-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 7:
- o.center_block("Bank+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 8:
- o.center_block("Pitch-", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 9:
- o.center_block("Pitch+", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
-
-
-
- if _id == 12:
- if o.odub == True:
- o.center_block("Odub", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.pink)
- else:
- o.center_block("Odub", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 13:
- o.center_block("Undo", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
-
-
- o_x = o_x + x_size
- _id += 1
- if _id % 4 == 0:
- o_y -= y_size
- o_x = og_x
-
- def draw_menu2_pattern(o):
- bpm_inc = 4
- x_size = o.width / 4
- y_size = o.height / 4
- og_x = 0
- o_x = og_x
- o_y = o.height
- text_padding = 6
- _id = 0
- while _id < 16:
-
- o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.dark_grey)
-
- if _id == 0:
- o.center_block("Copy", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 1:
- o.center_block("Paste", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 2:
- o.center_block("Clear", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 6:
- o.center_block("Bank -", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 7:
- o.center_block("Bank +", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
-
- o_x = o_x + x_size
- _id += 1
- if _id % 4 == 0:
- o_y -= y_size
- o_x = og_x
-
- def draw_menu2_note(o):
- bpm_inc = 4
- x_size = o.width / 4
- y_size = o.height / 4
- og_x = 0
- o_x = og_x
- o_y = o.height
- text_padding = 6
- _id = 0
- while _id < 16:
-
- o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.dark_grey)
-
- if _id == 0:
- o.center_block("Vol -", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- elif _id == 1:
- o.center_block("Vol +", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- elif _id == 12:
- if o.patternFollow:
- o.center_block("Follow", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.pink)
- else:
- o.center_block("Follow", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
-
-
- o_x = o_x + x_size
- _id += 1
- if _id % 4 == 0:
- o_y -= y_size
- o_x = og_x
-
- def draw_menu2_song(o):
- bpm_inc = 4
- x_size = o.width / 4
- y_size = o.height / 4
- og_x = 0
- o_x = og_x
- o_y = o.height
- text_padding = 6
- _id = 0
- while _id < 16:
-
- o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.dark_grey)
-
- if _id == 6:
- o.center_block("Bank -", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
- if _id == 7:
- o.center_block("Bank +", o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
-
- o_x = o_x + x_size
- _id += 1
- if _id % 4 == 0:
- o_y -= y_size
- o_x = og_x
-
-
- def menu1_actions(self, o):
- if o.keyState[16] == 2:
- if o.keyState[0] == 1:
- self.FSM.ToTransition('toMain')
- elif o.keyState[1] == 1:
- self.FSM.ToTransition('toEditSoundSequence')
- elif o.keyState[2] == 1:
- self.FSM.ToTransition('toSelectPattern')
- elif o.keyState[3] == 1:
- self.FSM.ToTransition('toEditSong')
- elif o.keyState[4] == 1:
- self.FSM.ToTransition('toFile')
- elif o.keyState[5] == 1:
- self.FSM.ToTransition('toUtil')
- if o.keyState[12] == 1:
- o.start_playback()
- play_seq(o, [o.curPattern, 0])
- if o.keyState[13] == 1:
- o.stop_playback()
- # if o.keyState[6] == 1:
- # if o.note_bank > 0:
- # o.note_bank -= 1
- # if o.keyState[7] == 1:
- # if o.note_bank < 3:
- # o.note_bank += 1
- if o.keyState[8] == 1:
- if o.volume > 0:
- o.volume -= 1
- text_center(o, "Master Volume", str(o.volume))
- o.update_display(0)
- if o.keyState[9] == 1:
- if o.volume < 16:
- o.volume += 1
- text_center(o, "Master Volume", str(o.volume))
- o.update_display(0)
- if o.keyState[11] == 1:
- #o.save_song()
- pass
- if o.keyState[14] == 1:
- if o.bpm > 60:
- o.bpm = o.bpm - o.bpm_inc
- o.update_bpm()
- text_center(o, "Master BPM", str(o.bpm))
- o.update_display(0)
- if o.keyState[15] == 1:
- if o.bpm < 240:
- o.bpm = o.bpm + o.bpm_inc
- o.update_bpm()
- text_center(o, "Master BPM", str(o.bpm))
- o.update_display(0)
-
-
- def menu2_actions_sample(self, o):
- if o.keyState[17] == 2:
- if o.keyState[0] == 1:
- if o.soundSlots[o.eSound].volume > 0:
- print('copy')
- o.soundClipboard = [o.soundSlots[o.eSound].file, o.soundSlots[o.eSound].volume, o.soundSlots[o.eSound].pitch]
- print(o.soundClipboard)
- #text_center(o, "Sample Volume", str(o.soundSlots[o.eSound].volume))
- #o.update_display(0)
- elif o.keyState[1] == 1:
-
- print('pasting ', o.soundClipboard)
-
- o.soundSlots[o.eSound].file = o.soundClipboard[0]
- o.soundSlots[o.eSound].volume = o.soundClipboard[1]
- o.soundSlots[o.eSound].pitch = o.soundClipboard[2]
- o.soundSlots[o.eSound].create_sound()
- o.soundSlots[o.eSound].set_pitch()
-
- #s = o.SoundSlot(o.soundClipboard[0], o.eSound, o)
- #s.volume = o.soundClipboard[1]
- #s.pitch = o.soundClipboard[2]
- #s.notes = s.init_notes()
- #o.soundSlots[o.eSound] = s
-
- elif o.keyState[2] == 1:
- print('delete sound ', o.eSound)
- o.soundSlots[o.eSound].file = None
- o.soundSlots[o.eSound].volume = 16
- o.soundSlots[o.eSound].pitch = 0
- elif o.keyState[3] == 1:
- print('load')
- o.FSM.FSM.ToTransition("toLoadSound")
-
- elif o.keyState[4] == 1:
- if o.soundSlots[o.eSound].volume > 0:
- o.soundSlots[o.eSound].volume -= 1
- text_center(o, "Sample Volume", str(o.soundSlots[o.eSound].volume))
- o.update_display(0)
-
- elif o.keyState[5] == 1:
- if o.soundSlots[o.eSound].volume < 16:
- o.soundSlots[o.eSound].volume += 1
- text_center(o, "Sample Volume", str(o.soundSlots[o.eSound].volume))
- o.update_display(0)
-
- elif o.keyState[6] == 1:
- if o.note_bank > 0:
- o.note_bank -= 1
- text_center(o, "Sound Bank", str(o.note_bank))
- o.update_display(0)
- elif o.keyState[7] == 1:
- if o.note_bank < 3:
- o.note_bank += 1
- text_center(o, "Sound Bank", str(o.note_bank))
- o.update_display(0)
-
- elif o.keyState[8] == 1:
- if o.soundSlots[o.eSound].pitch > -10:
- o.soundSlots[o.eSound].pitch -= 1
- text_center(o, "Sample Pitch", str(o.soundSlots[o.eSound].pitch))
- o.soundSlots[o.eSound].set_pitch()
- o.update_display(0)
- elif o.keyState[9] == 1:
- if o.soundSlots[o.eSound].pitch < 10:
- o.soundSlots[o.eSound].pitch += 1
- text_center(o, "Sample Pitch", str(o.soundSlots[o.eSound].pitch))
- o.soundSlots[o.eSound].set_pitch()
- o.update_display(0)
- elif o.keyState[12] == 1:
- o.odub = not o.odub
- o.undo_buf = []
- print('odub now is ', o.odub)
- draw_menu2_sample(o)
- o.update_display(0)
- elif o.keyState[13] == 1:
- print('undo something')
- for i in o.undo_buf:
- o.soundSlots[i[0]].notes[i[1]][i[2]][0] = 0
- o.soundSlots[i[0]].notes[i[1]][i[2]][1] = 0
- o.undo_buf = []
-
- def menu2_actions_pattern(self, o):
- if o.keyState[17] == 2:
- if o.keyState[0] == 1:
- print('copy')
- o.patternClipboard = []
- for s in o.soundSlots:
- notes = []
- for i in s.notes[o.ePattern]:
- notes.append([i[0], i[1]])
- #i[0] = 0
- #i[1] = 0
- o.patternClipboard.append(notes)
- print('adding to clip ', notes)
- # if o.soundSlots[o.eSound].volume > 0:
- # o.soundSlots[o.eSound].volume -= 1
- # text_center(o, "Sample Volume", str(o.soundSlots[o.eSound].volume))
- # o.update_display(0)
- elif o.keyState[1] == 1:
- print('paste')
- if o.patternClipboard != []:
- p = 0
- for s in o.soundSlots:
- n = 0
- for i in s.notes[o.ePattern]:
- i[0] = o.patternClipboard[p][n][0]
- i[1] = o.patternClipboard[p][n][1]
- n += 1
- print('added ', o.patternClipboard[p])
- p += 1
-
-
- else:
- print('nothing to paste')
- # if o.soundSlots[o.eSound].volume < 16:
- # o.soundSlots[o.eSound].volume += 1
- # text_center(o, "Sample Volume", str(o.soundSlots[o.eSound].volume))
- # o.update_display(0)
- elif o.keyState[2] == 1:
- print('clear')
- print(o.soundSlots[o.eSound].notes[o.ePattern])
- for s in o.soundSlots:
- for i in s.notes[o.ePattern]:
- i[0] = 0
- i[1] = 0
- #print(o.soundSlots[o.eSound].notes[o.ePattern])
- # if o.soundSlots[o.eSound].pitch > -10:
- # o.soundSlots[o.eSound].pitch -= 1
- # text_center(o, "Sample Pitch", str(o.soundSlots[o.eSound].pitch))
- # o.soundSlots[o.eSound].set_pitch()
- # o.update_display(0)
- elif o.keyState[6] == 1:
- if o.pat_bank > 0:
- o.pat_bank -= 1
- text_center(o, "Pattern Bank", str(o.pat_bank))
- o.update_display(0)
-
- elif o.keyState[7] == 1:
- if o.pat_bank < 3:
- o.pat_bank += 1
- text_center(o, "Pattern Bank", str(o.pat_bank))
- o.update_display(0)
-
- def menu2_actions_song(self, o):
- if o.keyState[17] == 2:
-
- if o.keyState[6] == 1:
- if o.pat_bank > 0:
- o.pat_bank -= 1
- text_center(o, "Pattern Bank", str(o.pat_bank))
- o.update_display(0)
- elif o.keyState[7] == 1:
- if o.pat_bank < 3:
- o.pat_bank += 1
- text_center(o, "Pattern Bank", str(o.pat_bank))
- o.update_display(0)
-
-
-
-
- def menu2_actions_note(self, o):
- if o.keyState[17] == 2:
- if o.keyState[0] == 1:
- if o.note_vol > 0:
- o.note_vol -= 1
- text_center(o, "Note Volume", str(o.note_vol))
- o.update_display(0)
-
- elif o.keyState[1] == 1:
- if o.note_vol < 16:
- o.note_vol += 1
- text_center(o, "Note Volume", str(o.note_vol))
- o.update_display(0)
- elif o.keyState[12] == 1:
- if o.patternFollow:
- o.patternFollow = False
- else:
- o.patternFollow = True
- #o.patternFollow != o.patternFollow
- print('pattern follow is ', o.patternFollow)
- draw_menu2_note(o)
- o.update_display(0)
-
-
-
-
-
- def util_command(self, o, command):
- if command == "Clock":
- self.FSM.ToTransition('toClock')
- elif command == "Balls":
- self.FSM.ToTransition('toBall')
- elif command == "Defender":
- self.FSM.ToTransition('toDefender')
- elif command == "Exit":
- self.FSM.ToTransition('toExit')
- elif command == "Theme":
- self.FSM.ToTransition('toSelTheme')
- elif command == "Reboot":
- self.FSM.ToTransition('toReboot')
- elif command == "Update":
- self.FSM.ToTransition('toUpdate')
- #os.system("sudo reboot")
- elif command == "Shutdown":
- self.FSM.ToTransition('toShutdown')
- elif command == "Ping":
- self.FSM.ToTransition('toPing')
- elif command == "Wifi":
- self.FSM.ToTransition('toWifi')
-
- def file_command(self, o, command):
- if command == "Save":
- if o.sconf['title'] != "blank":
- o.save_song()
- else:
- print('cant save over blank')
-
- elif command == "Open":
- self.FSM.ToTransition('toOpenSong')
- elif command == "Save As":
- self.FSM.ToTransition('toEnterText')
- elif command == "New":
- #self.FSM.ToTransition('toEnterText')
- #o.title = '_blank'
- o.mconf['default_song'] = '_blank'
- o.load_song()
- #====================================
-
- class Example(State):
- def __init__(self,FSM):
- super(Example, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- super(Example, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
-
- def Exit(self):
- pass
-
- #====================================
-
- class Startup(State):
- def __init__(self,FSM):
- super(Startup, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- self.birth = time.perf_counter()
- super(Startup, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
- print('startup state')
-
- if hasattr(self, 'birth'):
- pass
- else:
- self.birth = time.perf_counter()
-
- self.FSM.ToTransition('toIntro')
-
- def Exit(self):
- pass
-
- #====================================
-
- class Intro(State):
- def __init__(self,FSM):
- super(Intro, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- o = self.FSM.owner
- o.header_text = "Starting up..."
- o.draw.rectangle((0, 0, self.FSM.owner.width, self.FSM.owner.height), outline=0, fill=o.blue)
- #draw_header(o)
- #o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
- o.center_block("Starting up...", o.h2, [0, 0, o.width, o.height], o.light_grey)
- #o.display_thread.start()
- o.update_display(0)
- #o.update_display(0)
- super(Intro, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
- o = self.FSM.owner
- self.FSM.ToTransition('toLoadDefault')
-
- def Exit(self):
- pass
-
- #====================================
-
- class LoadDefault(State):
- def __init__(self,FSM):
- super(LoadDefault, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
-
-
- o = self.FSM.owner
- o.init_slots()
- o.load_song()
-
-
-
- self.bank = 0
- self.sounds = []
- self.globbed = glob.glob('/home/pi/skull/*.wav') + glob.glob('/home/pi/skull/*.mp3')
- self.globbed.sort()
- obj_id = 0
-
- # for s in o.sconf['sounds']:
- # p1 = self.FSM.owner.SoundSlot(s, obj_id, o)
- # self.FSM.owner.soundSlots.append(p1)
- # obj_id += 1
-
- # _iter = 0
-
- # lst = ast.literal_eval(o.sconf['notes'][0])
- # print('length ', len(lst))
-
- # for n in o.soundSlots:
- # m = []
- # if _iter < (len(o.sconf.as_list('notes')) - 1):
- # lst = ast.literal_eval(o.sconf.as_list('notes')[_iter])
- # n.notes = lst
- # _iter += 1
-
- super(LoadDefault, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
- self.FSM.ToTransition('toMain')
-
- def Exit(self):
- pass
-
- #====================================
-
- #====================================
-
- class Main(State):
- def __init__(self,FSM):
- super(Main, self).__init__(FSM)
-
- def Enter(self):
- print('hello main')
- self.FSM.owner.pub.register("beat", self)
- self.FSM.stateLife = 1
- o = self.FSM.owner
- o.header_text = "Sound Select"
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- draw_header(o)
- self.draw_square()
-
- text_box1(o, "Vol", str(o.soundSlots[o.eSound].volume))
- text_box2(o, "BPM", str(o.bpm))
- text_box4(o, "Bank", str(o.note_bank))
- text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
- o.update_display(0)
-
- #o.soundSlots[2].volume = 2
- self.recording = True
- self.record_queue = []
- self.undo_queue = []
- super(Main, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- menu1_actions(self, o)
- menu2_actions_sample(self, o)
- #self.FSM.ToTransition('toClock')
- if o.keyState[16] == 1:
- draw_menu1(o)
- o.update_display(0)
- elif o.keyState[16] == 4:
- draw_header(o)
- self.draw_square()
- #print('esound ', o.eSound)
- #print('oss ', o.soundSlots[o.eSound].volume)
- text_box1(o, "Vol", str(o.soundSlots[o.eSound].volume))
- text_box2(o, "BPM", str(o.bpm))
- text_box4(o, "Bank", str(o.note_bank))
- text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
- o.update_display(0)
-
-
- if o.keyState[17] == 1:
- draw_menu2_sample(o)
- o.update_display(0)
- elif o.keyState[17] == 4:
- draw_header(o)
- self.draw_square()
- text_box1(o, "Vol", str(o.soundSlots[o.eSound].volume))
- text_box2(o, "BPM", str(o.bpm))
- text_box4(o, "Bank", str(o.note_bank))
- text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
- o.update_display(0)
-
- _id = 0
- for k in o.keyState:
- if _id > 15:
- pass
- else:
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- if k == 1:
- note = _id + o.note_bank * 16
- self.record_queue = pygame.time.get_ticks()
- print('bpm is ', o.half_bpm, ' ', self.record_queue)
-
- o.soundSlots[note].play(o.note_vol)
- o.eSound = note
- print('now editing sound ', o.eSound)
- draw_header(o)
- #text_box1(o, "SVol", str(o.soundSlots[o.eSound].volume))
- text_box1(o, "SVol", str(o.slots[o.eSound].volume))
- text_box2(o, "BPM", str(o.bpm))
- text_box4(o, "Bank", str(o.note_bank))
- #text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
- text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
- self.draw_square()
- o.update_display(0)
- _id += 1
-
- def ReceiveMessage(self, message):
- o = self.FSM.owner
- play_seq(o, message)
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- draw_header(o)
- self.draw_square()
- text_box1(o, "SVol", str(o.soundSlots[o.eSound].volume))
- text_box2(o, "BPM", str(o.bpm))
- text_box4(o, "Bank", str(o.note_bank))
- text_box3(o, "Pitch", str(o.soundSlots[o.eSound].pitch))
- o.update_display(0)
- if self.record_queue != []:
- cur_time = pygame.time.get_ticks()
- note_pos = (cur_time - self.record_queue) - (o.half_bpm / 2)
- print(note_pos)
- if o.odub == True:
- if note_pos > (o.half_bpm):
- _note = 0
- if message[1] == 0:
- _note = 15
- else:
- _note = message[1] - 1
-
- if o.soundSlots[o.eSound].notes[message[0]][_note][0] != 1:
- o.soundSlots[o.eSound].notes[message[0]][_note][0] = 1
- o.soundSlots[o.eSound].notes[message[0]][_note][1] = o.note_vol
- o.undo_buf.append([o.eSound, message[0], _note])
- print(o.undo_buf)
-
- else:
- if o.soundSlots[o.eSound].notes[message[0]][message[1]][0] != 1:
- o.soundSlots[o.eSound].notes[message[0]][message[1]][0] = 1
- o.soundSlots[o.eSound].notes[message[0]][message[1]][1] = o.note_vol
- o.undo_buf.append([o.eSound, message[0], message[1]])
- print(o.undo_buf)
-
- self.record_queue = []
-
-
- def draw_square(self):
- o = self.FSM.owner
- size = 22
- og_x = (o.width / 2) - (size * 2)
- o_x = og_x
- o_y = 127
- _id = o.note_bank * 16
-
- while _id < ((o.note_bank * 16) + 16):
- if _id == o.eSound:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1)
- elif o.notes_on[_id] == 1:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.grey, width=1)
- #elif _id > (len(o.soundSlots) - 1):
- elif self.has_sample(o, _id) == False:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.dark_grey, width=1)
-
-
- else:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
- o_x = o_x + size
- _id += 1
- if _id % 4 == 0:
- o_y -= size
- o_x = og_x
-
- def has_sample(self, o, slot):
- if o.soundSlots[slot].file != None:
- return True
- else:
- return False
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
- #====================================
- #====================================
-
- class PadPlayer(State):
- def __init__(self,FSM):
- super(PadPlayer, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- print('entering pad player')
- super(PadPlayer, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
-
-
- _id = 0
- for k in self.FSM.owner.keyState:
- if _id < 16 and k == 1:
- self.FSM.owner.soundSlots[_id].play()
- _id += 1
- if self.FSM.owner.keys:
-
- print("Pressed: ", self.FSM.owner.keys)
- #self.FSM.ToTransition('toLand')
-
- def Exit(self):
- pass
-
- #====================================
-
- class SeqPlayer(State):
- def __init__(self,FSM):
- super(SeqPlayer, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- self.beat = 0
- self.FSM.owner.pub.register("beat", self)
- print('entering seq player')
- o = self.FSM.owner
- o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
- o.draw.text((20, 0), 'SeqPlayer', font=o.h1, fill="#FFFFFF")
- o.update_display(0)
- super(SeqPlayer, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
- o = self.FSM.owner
-
- if o.keyState[12] == 1:
- o.start_playback()
- play_seq(o, [o.curPattern, 0])
- if o.keyState[13] == 1:
- o.stop_playback()
- #self.beat = o.playhead
- #print('key0 ', o.keyState[16])
- if o.keyState[16] == 2:
- #print('key0 ', o.keyState[16])
- if o.keyState[0] == 1:
- print('to main')
- self.FSM.ToTransition('toMain')
-
- def ReceiveMessage(self, message):
- #print(self.name, 'got message', message)
- o = self.FSM.owner
- o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
- o.draw.text((20, 0), str(message[0]) + ' - ' + str(message[1]), font=o.h1, fill="#FFFFFF")
- o.update_display(0)
- play_seq(o, message)
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
- #====================================
- #====================================
-
- class SelectSound(State):
- def __init__(self,FSM):
- super(SelectSound, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- o = self.FSM.owner
- o.header_text = "SelSou"
- o.pub.register("beat", self)
- draw_header(o)
- self.draw_square()
- o.update_display(0)
- super(SelectSound, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- if o.keyState[16] == 1:
- draw_menu1(o)
- o.update_display(0)
- elif o.keyState[16] == 4:
- draw_header(o)
- self.draw_square()
- o.update_display(0)
-
- if o.keyState[16] == 2:
- if o.keyState[0] == 1:
- self.FSM.ToTransition('toMain')
- else:
- _id = 0
- for k in o.keyState:
- if _id > 15:
- pass
- else:
- if k == 1:
- o.eSound = _id
- o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
- o.draw.text((0, 0), "SelSou", font=o.h1, fill=o.light_blue)
- o.draw.text((20, 60), str(o.eSound), font=o.h2, fill=o.light_grey)
- self.draw_square()
- o.update_display(0)
- self.FSM.owner.soundSlots[_id].play()
- #print('now editing sound ', _id)
- _id += 1
-
- def ReceiveMessage(self, message):
- _id = 0
- o = self.FSM.owner
- o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=(0, 0, 0))
- o.draw.text((0, 0), "SelSou", font=o.h1, fill="#FFFFFF")
- o.draw.text((0, 20), str(o.eSound), font=o.h2, fill="#FFFFFF")
- o.update_display(0)
- play_seq(o, message)
-
- def draw_square(self):
- o = self.FSM.owner
- size = 32
- og_x = 110
- o_x = og_x
- o_y = 0
- _id = 0
-
- for n in o.soundSlots[o.eSound].notes[o.ePattern]:
- if _id == o.eSound:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y + size), outline=0, fill=o.light_grey)
- else:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y + size), outline=0, fill=o.dark_grey)
- o_x = o_x + size
- _id += 1
- if _id % 4 == 0:
- o_y += size
- o_x = og_x
-
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
- #====================================
-
- class SelectPattern(State):
- def __init__(self,FSM):
- super(SelectPattern, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- o = self.FSM.owner
- o.header_text = "Select Pattern"
- o.pub.register("beat", self)
- self.cur_playing = 0
- self.active_patterns = []
- self.get_active_patterns(o)
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- draw_header(o)
- self.draw_square()
- text_box1(o, "Pat", str(o.ePattern))
- text_box4(o, "Bank", str(o.pat_bank))
- o.update_display(0)
-
- super(SelectPattern, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- menu1_actions(self, o)
- menu2_actions_pattern(self, o)
- if o.keyState[16] == 1:
- draw_menu1(o)
- o.update_display(0)
- elif o.keyState[16] == 4:
- draw_header(o)
- self.draw_square()
- text_box1(o, "Pat", str(o.ePattern))
- text_box4(o, "Bank", str(o.pat_bank))
- o.update_display(0)
-
- if o.keyState[17] == 1:
- draw_menu2_pattern(o)
- o.update_display(0)
- elif o.keyState[17] == 4:
- draw_header(o)
- self.get_active_patterns(o)
- self.draw_square()
- text_box1(o, "Pat", str(o.ePattern))
- text_box4(o, "Bank", str(o.pat_bank))
-
- o.update_display(0)
-
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- _id = 0
- for k in o.keyState:
- if _id > 15:
- pass
- else:
- if k == 1:
- o.ePattern = (o.pat_bank * 16) +_id
-
- draw_header(o)
- self.draw_square()
-
- text_box1(o, "Pat", str(o.ePattern))
- text_box4(o, "Bank", str(o.pat_bank))
- o.update_display(0)
-
-
- _id += 1
-
- def ReceiveMessage(self, message):
- o = self.FSM.owner
- play_seq(o, message)
-
- if message[0] != self.cur_playing:
- #print('playing ', message)
- self.cur_playing = message[0]
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- draw_header(o)
- self.draw_square()
- text_box1(o, "Pat", str(o.ePattern))
- text_box4(o, "Bank", str(o.pat_bank))
- o.update_display(0)
-
- def draw_square(self):
- o = self.FSM.owner
- size = 22
- og_x = (o.width / 2) - (size * 2)
- o_x = og_x
- o_y = 127
- _id = 0
- for n in o.soundSlots[o.eSound].notes[o.ePattern]:
- if (_id + (o.pat_bank * 16)) == o.ePattern:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.olive, width=1)
- elif (_id + (o.pat_bank * 16)) == self.cur_playing:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1)
- elif self.active_patterns[_id] == 1:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
- else:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.dark_grey, width=1)
- o_x = o_x + size
- _id += 1
- if _id % 4 == 0:
- o_y -= size
- o_x = og_x
-
- def get_active_patterns(self, o):
- #for n in o.soundSlots[o.eSound]
- self.active_patterns = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
- pat_iter = o.pat_bank * 16
- _iter = 0
- print('is this note on? ', o.soundSlots[0].notes[0][0][0])
-
-
- while pat_iter < ((o.pat_bank * 16) + 16):
-
- for s in o.soundSlots:
- print('checking soundSlot ', s.id)
- pat_used = 0
- for p in s.notes[pat_iter]:
- if self.active_patterns[_iter] == 1:
- break
- if p[0] == 1:
- #pat_used = 1
- self.active_patterns[_iter] = 1
- print('found ', pat_iter, ' -- ', p[0])
- break
- #self.active_patterns.append(pat_used)
- pat_iter += 1
- _iter += 1
-
- print('active patterns ', self.active_patterns)
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
- #====================================
-
- class EditSoundSequence(State):
- def __init__(self,FSM):
- super(EditSoundSequence, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- o = self.FSM.owner
- o.header_text = "Note Edit"
- o.pub.register("beat", self)
- self.curPattern = o.ePattern
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- draw_header(o)
- self.draw_square()
- text_box1(o, "Note Vol", str(o.note_vol))
- text_box3(o, "Pat", str(self.curPattern))
- o.update_display(0)
- super(EditSoundSequence, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- menu1_actions(self, o)
- menu2_actions_note(self, o)
- if o.keyState[16] == 1:
- draw_menu1(o)
- o.update_display(0)
- elif o.keyState[16] == 4:
- draw_header(o)
- self.draw_square()
- text_box1(o, "Note Vol", str(o.note_vol))
- text_box3(o, "Pat", str(self.curPattern))
- o.update_display(0)
-
- if o.keyState[17] == 1:
- draw_menu2_note(o)
- o.update_display(0)
- elif o.keyState[17] == 4:
- draw_header(o)
- self.draw_square()
- text_box1(o, "Note Vol", str(o.note_vol))
- text_box3(o, "Pat", str(self.curPattern))
- o.update_display(0)
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
-
- else:
- _id = 0
- for k in self.FSM.owner.keyState:
- if _id < 16 and k == 1:
- if o.soundSlots[o.eSound].notes[self.curPattern][_id][0] == 1:
- print('turn note off')
- o.soundSlots[o.eSound].notes[self.curPattern][_id][0] = 0
- o.soundSlots[o.eSound].notes[self.curPattern][_id][1] = 0
- else:
- print('turn note on')
- o.soundSlots[o.eSound].notes[self.curPattern][_id][0] = 1
- o.soundSlots[o.eSound].notes[self.curPattern][_id][1] = o.note_vol
- draw_header(o)
- self.draw_square()
- text_box1(o, "Note Vol", str(o.note_vol))
- text_box3(o, "Pat", str(self.curPattern))
- o.update_display(0)
- _id += 1
-
-
-
- def draw_square(self):
- o = self.FSM.owner
- size = 22
- og_x = (o.width / 2) - (size * 2)
- o_x = og_x
- o_y = 127
- _id = 0
- for n in o.soundSlots[o.eSound].notes[self.curPattern]:
- if _id == o.playhead and o.playing:
- if o.curPattern == self.curPattern:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.olive, width=1)
- else:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.pink, width=1)
- elif n[0] == 1:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.light_grey, width=1)
- else:
- o.draw.rectangle((o_x, o_y, o_x + size, o_y - size), outline=o.light_grey, fill=o.blue, width=1)
- o_x = o_x + size
- _id += 1
- if _id % 4 == 0:
- o_y -= size
- o_x = og_x
-
- def ReceiveMessage(self, message):
- _id = 0
- o = self.FSM.owner
- play_seq(o, message)
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- draw_header(o)
- self.draw_square()
- text_box1(o, "Note Vol", str(o.note_vol))
- text_box3(o, "Pat", str(self.curPattern))
- if o.patternFollow:
- self.curPattern = message[0]
- else:
- self.curPattern = o.ePattern
- print('message ', message)
- o.update_display(0)
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
-
- class EditSong(State):
- def __init__(self,FSM):
- super(EditSong, self).__init__(FSM)
-
- def Enter(self):
- o = self.FSM.owner
- o.header_text = "Edit Song"
- o.pub.register("beat", self)
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- draw_header(o)
- self.draw_main(o)
- # o.draw.text((20, 30), "Current Song", font=o.h2, fill=o.light_grey)
- # o.draw.text((20, 50), str(o.song), font=o.h2, fill=o.light_grey)
- o.update_display(0)
- self.new_song = []
- super(EditSong, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
-
- menu1_actions(self, o)
- menu2_actions_song(self, o)
- if o.keyState[16] == 1:
- draw_menu1(o)
- o.update_display(0)
- elif o.keyState[16] == 4:
- draw_header(o)
- self.draw_main(o)
- # if self.new_song == []:
- # o.draw.text((20, 30), "Current Song", font=o.h2, fill=o.light_grey)
- # o.draw.text((20, 50), str(o.song), font=o.h2, fill=o.light_grey)
- # else:
- # o.draw.text((20, 30), "New Song", font=o.h2, fill=o.pink)
- # o.draw.text((20, 50), str(self.new_song), font=o.h2, fill=o.pink)
- o.update_display(0)
-
- if o.keyState[17] == 1:
- draw_menu2_song(o)
- o.update_display(0)
- elif o.keyState[17] == 4:
- draw_header(o)
- self.draw_main(o)
- o.update_display(0)
- if o.keyState[16] > 0 or o.keyState[17] > 0:
-
- #if o.keyState[16] > 0:
- pass
- else:
- _id = 0
- for k in self.FSM.owner.keyState:
- if k == 1 and _id < 16:
- self.new_song.append((_id + (o.pat_bank * 16)))
- draw_header(o)
- self.draw_main(o)
- #o.draw.text((20, 30), "New Song", font=o.h2, fill=o.pink)
- #o.draw.text((20, 50), str(self.new_song), font=o.h2, fill=o.pink)
- o.update_display(0)
- _id += 1
-
-
- def draw_main(self, o):
- ypos = 35
- ysize = 20
- tmp_song = [8, 6, 7, 5, 3, 0, 9]
- lines = breakup_song_text(o.song)
- #lines = breakup_song_text(tmp_song)
-
- if self.new_song != []:
- #o.draw.text((20, 30), "New Song", font=o.h2, fill=o.pink)
- lines = breakup_song_text(self.new_song)
- o.center_block("New Song", o.h2, [0, ypos, o.width, ypos + ysize], o.pink)
- else:
- #o.draw.text((20, 30), "Current Song", font=o.h2, fill=o.light_grey)
- o.center_block("Current Song", o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
-
- ypos += ysize
- o.center_block(lines[0], o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
- ypos += ysize
- o.center_block(lines[1], o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
- ypos += ysize
- o.center_block(lines[2], o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
- ypos += ysize
- o.center_block(lines[3], o.h2, [0, ypos, o.width, ypos + ysize], o.light_grey)
-
- def ReceiveMessage(self, message):
- _id = 0
- o = self.FSM.owner
- play_seq(o, message)
-
- def Exit(self):
- o = self.FSM.owner
- self.FSM.owner.pub.unregister("beat", self)
- if self.new_song != []:
- o.song = self.new_song
- o.songCycle = cycle(self.new_song)
- self.curPattern = next(o.songCycle)
- o.songStart = o.curPattern
-
- #====================================
-
- class File(State):
- def __init__(self,FSM):
- super(File, self).__init__(FSM)
-
- def Enter(self):
- self.FSM.stateLife = 1
- o = self.FSM.owner
- o.header_text = "File"
- o.pub.register("beat", self)
- self.cur_el = 0
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- draw_header(o)
- self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
- self.menu = ["Save", "Save As", "Open", "New"]
-
- super(File, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- menu1_actions(self, o)
- if o.keyState[16] == 1:
- draw_menu1(o)
- #self.draw_footer(o)
- o.update_display(0)
- elif o.keyState[16] == 4:
- draw_header(o)
- self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
-
- if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
- draw_header(o)
- self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
- print('draw butt')
-
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- if o.keyState[0] == 1:
- if self.cur_el > 0:
- self.cur_el -= 1
- print('cur el down is ', self.cur_el)
- if o.keyState[1] == 1:
- if self.cur_el < (len(self.menu) - 1):
- self.cur_el += 1
- print('cur el up is ', self.cur_el)
-
- if o.keyState[3] == 1:
- file_command(self, o, self.menu[self.cur_el])
- pass
-
- def draw_footer(self, o):
- _iter = 0
- width = o.width / 4
- xpos = 0
- yposa = 135 - 25
- yposb = 135
- opts = ["Up", "Down", "Esc", "OK"]
- while _iter < 4:
- o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
-
- if o.keyState[_iter] == 1:
- o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
- o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
- else:
- o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
-
- xpos += width
- _iter += 1
-
-
- def draw_main(self, o):
- al = []
- ypos = 30
- if self.cur_el == 0:
- _iter = 0
- while len(al) < 4:
- al.append(self.menu[_iter])
- _iter += 1
- elif self.cur_el == 1:
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- al.append(self.menu[self.cur_el + 1])
- al.append(self.menu[self.cur_el + 2])
- elif self.cur_el == (len(self.menu) - 2):
- al.append(self.menu[self.cur_el - 2])
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- al.append(self.menu[self.cur_el + 1])
- elif self.cur_el == (len(self.menu) - 1):
- al.append(self.menu[self.cur_el - 3])
- al.append(self.menu[self.cur_el - 2])
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- else:
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- al.append(self.menu[self.cur_el + 1])
- al.append(self.menu[self.cur_el + 2])
- _iter = 0
- for i in al:
- if i == self.menu[self.cur_el]:
- #if _iter == self.cur_el:
- o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.light_grey)
- o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.blue)
- else:
- o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.blue)
- o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.light_grey)
- ypos += 20
- _iter += 1
-
- def ReceiveMessage(self, message):
- o = self.FSM.owner
- play_seq(o, message)
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
- class Util(State):
- def __init__(self,FSM):
- super(Util, self).__init__(FSM)
-
- def Enter(self):
- o = self.FSM.owner
- o.header_text = "Utilities"
- o.pub.register("beat", self)
- self.menu = ["Clock", "Balls", "Defender", "Exit", "Shutdown", "Reboot", "Theme", "Ping", "Wifi", "Update"]
- self.cur_el = 0
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- draw_header(o)
- self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
-
-
- super(Util, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- menu1_actions(self, o)
- if o.keyState[16] == 1:
- draw_menu1(o)
- o.update_display(0)
- elif o.keyState[16] == 4:
- draw_header(o)
- self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
-
- if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
- draw_header(o)
- self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
- print('draw butt')
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- if o.keyState[0] == 1:
- if self.cur_el > 0:
- self.cur_el -= 1
- print('cur el down is ', self.cur_el)
- if o.keyState[1] == 1:
- if self.cur_el < (len(self.menu) - 1):
- self.cur_el += 1
- print('cur el up is ', self.cur_el)
-
- if o.keyState[3] == 1:
- util_command(self, o, self.menu[self.cur_el])
-
- def ReceiveMessage(self, message):
- _id = 0
- o = self.FSM.owner
- play_seq(o, message)
- # if o.keyState[16] > 0 or o.keyState[17] > 0:
- # pass
- # else:
- # draw_header(o)
- # o.update_display(0)
-
- def draw_main(self, o):
- al = []
- ypos = 30
- if self.cur_el == 0:
- _iter = 0
- while len(al) < 4:
- al.append(self.menu[_iter])
- _iter += 1
- elif self.cur_el == 1:
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- al.append(self.menu[self.cur_el + 1])
- al.append(self.menu[self.cur_el + 2])
- elif self.cur_el == (len(self.menu) - 2):
- al.append(self.menu[self.cur_el - 2])
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- al.append(self.menu[self.cur_el + 1])
- elif self.cur_el == (len(self.menu) - 1):
- al.append(self.menu[self.cur_el - 3])
- al.append(self.menu[self.cur_el - 2])
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- else:
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- al.append(self.menu[self.cur_el + 1])
- al.append(self.menu[self.cur_el + 2])
- _iter = 0
- for i in al:
- if i == self.menu[self.cur_el]:
- #if _iter == self.cur_el:
- o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.light_grey)
- o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.blue)
- else:
- o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.blue)
- o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.light_grey)
- ypos += 20
- _iter += 1
-
- def draw_footer(self, o):
- _iter = 0
- width = o.width / 4
- xpos = 0
- yposa = 135 - 25
- yposb = 135
- opts = ["Up", "Down", "Esc", "OK"]
- while _iter < 4:
- o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
-
- if o.keyState[_iter] == 1:
- o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
- o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
- else:
- o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
-
- xpos += width
- _iter += 1
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
-
-
- class Ball(State):
- def __init__(self,FSM):
- super(Ball, self).__init__(FSM)
-
- def Enter(self):
- self.ball_size = 10
- self.ballx = self.ball_size
- self.bally = self.ball_size
-
- self.ball_speed = 8
- self.ball_x_dir = 1
- self.ball_y_dir = 1
-
- self.ball2x = self.ball_size + 180
- self.ball2y = self.ball_size + 70
-
- self.ball2_x_dir = -1
- self.ball2_y_dir = -1
-
- self.xmult = 1.0
-
- o = self.FSM.owner
- o.header_text = "Balls"
- o.pub.register("beat", self)
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- draw_header(o)
- o.update_display(0)
- super(Ball, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- menu1_actions(self, o)
- if o.keyState[16] == 1:
- draw_menu1(o)
- o.update_display(0)
-
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- now = datetime.now()
- current_time = time.strftime("%-I:%M %p")
-
-
- if self.ballx < (0 + self.ball_size):
- self.ball_x_dir = 1
- if self.ballx > (o.width - self.ball_size):
- self.ball_x_dir = -1
-
- if self.bally < (0 + self.ball_size):
- self.ball_y_dir = 1
- if self.bally > (o.height - self.ball_size):
- self.ball_y_dir = -1
-
- # if self.ballx > (o.width - self.ball_size) or self.ballx < (0 + self.ball_size):
- # self.ball_x_dir *= -1
- # if self.bally > (o.height - self.ball_size) or self.bally < (0 + self.ball_size):
- # self.ball_y_dir *= -1
-
- self.ballx += self.ball_speed * self.ball_x_dir
- self.bally += self.ball_speed * self.ball_y_dir
-
-
- if self.ball2x < (0 + self.ball_size):
- self.ball2_x_dir = 1
- self.xmult = random.uniform(.6, 1.2)
- if self.ball2x > (o.width - self.ball_size):
- self.ball2_x_dir = -1
- self.xmult = random.uniform(.6, 1.2)
-
- if self.ball2y < (0 + self.ball_size):
- self.ball2_y_dir = 1
- if self.ball2y > (o.height - self.ball_size):
- self.ball2_y_dir = -1
-
-
- # if self.ball2x > (o.width - self.ball_size) or self.ball2x < (0 + self.ball_size):
- # self.ball2_x_dir *= -1
- # self.xmult = random.uniform(.8, 1.2)
- # if self.ball2y > (o.height - self.ball_size) or self.ball2y < (0 + self.ball_size):
- # self.ball2_y_dir *= -1
-
- self.ball2x += (self.ball_speed * self.ball2_x_dir) * self.xmult
- self.ball2y += (self.ball_speed * self.ball2_y_dir)
-
- o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
-
- o.draw.ellipse((self.ballx - self.ball_size, self.bally - self.ball_size, self.ballx + self.ball_size, self.bally + self.ball_size), fill = o.light_grey, outline =o.light_grey)
- o.draw.ellipse((self.ball2x - self.ball_size, self.ball2y - self.ball_size, self.ball2x + self.ball_size, self.ball2y + self.ball_size), fill = o.light_grey, outline =o.light_grey)
- #o.center_block(current_time, o.h3, [0,0,o.width,o.height], o.pink)
- o.update_display(0)
-
- def ReceiveMessage(self, message):
- o = self.FSM.owner
- play_seq(o, message)
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
- #====================================
-
-
- class Clock(State):
- def __init__(self,FSM):
- super(Clock, self).__init__(FSM)
-
- def Enter(self):
- o = self.FSM.owner
- current_time = time.strftime("%-I:%M:%S")
- self.ball_sizex, self.ball_sizey = o.h3.getsize("18:88:88")
- self.ball_sizex /= 2
- self.ball_sizey /= 2
- #self.ball_sizey += 10
- self.ballx = o.width / 2
- self.bally = o.height / 2
- self.ball_speed = .5
- self.ball_x_dir = 1
- self.ball_y_dir = 1
-
- o.header_text = "Clock"
- o.pub.register("beat", self)
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- pass
- super(Clock, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- menu1_actions(self, o)
-
- if o.keyState[16] == 1:
- draw_menu1(o)
- o.update_display(0)
-
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- current_time = time.strftime("%-I:%M:%S")
- s = int(time.strftime("%S"))
- if s % 2 == 0:
- current_time = time.strftime("%-I:%M.%S")
-
- if self.ballx > (o.width - self.ball_sizex) or self.ballx < (0 + self.ball_sizex):
- self.ball_x_dir *= -1
- if (self.bally > o.height - self.ball_sizey - 20) or (self.bally < 0 + self.ball_sizey):
- self.ball_y_dir *= -1
-
- x1 = self.ballx - self.ball_sizex
- x2 = self.ballx + self.ball_sizex
- y1 = self.bally - self.ball_sizey
- y2 = self.bally + self.ball_sizey
- self.ballx += self.ball_speed * self.ball_x_dir
- self.bally += self.ball_speed * self.ball_y_dir
- o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
- #o.draw.rectangle((x1, y1, x2, y2), outline=0, fill=o.dark_grey)
-
- #o.draw.text((self.ballx - self.ball_sizex, self.bally - self.ball_sizey), current_time, align='center', font=o.h3, fill=o.light_grey)
- o.center_block(current_time, o.h3, [x1, y1, x2, y2], o.light_grey)
- today = date.today()
- current_date = today.strftime('%A')
- current_date += ', ' + today.strftime("%b %d, %Y")
- #o.draw.text((self.ballx - self.ball_sizex, (self.bally + 45) - self.ball_sizey), current_date, align='center', font=o.h2, fill=o.light_grey)
- o.center_block(current_date, o.h2, [x1, y1 + 35, x2, y2 + 35], o.light_grey)
- o.update_display(0)
-
- def ReceiveMessage(self, message):
- o = self.FSM.owner
- play_seq(o, message)
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
- #====================================
-
- class Exit(State):
- def __init__(self,FSM):
- super(Exit, self).__init__(FSM)
-
- def Enter(self):
- o = self.FSM.owner
- o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
- o.center_block("goodbye", o.h2, [0, 0, o.width,o.height], o.light_grey)
- o.update_display(0)
- pygame.quit()
- sys.exit()
- super(Exit, self).Enter()
-
- def Execute(self):
- self.FSM.stateLife += 1
-
- def Exit(self):
- pass
-
- #====================================
-
- #====================================
-
- class Reboot(State):
- def __init__(self,FSM):
- super(Reboot, self).__init__(FSM)
-
- def Enter(self):
- o = self.FSM.owner
- o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
- o.center_block("rebooting", o.h2, [0, 0, o.width,o.height], o.light_grey)
- o.update_display(0)
- command = 'bash -c "sleep 5; sudo shutdown -r now"&'
- os.system(command)
- pygame.quit()
- sys.exit()
- super(Reboot, self).Enter()
-
- def Execute(self):
- pass
- #self.FSM.stateLife += 1
- #os.system('sudo shutdown -r now')
-
- def Exit(self):
- pass
-
- #====================================
-
-
- #====================================
-
- class Shutdown(State):
- def __init__(self,FSM):
- super(Shutdown, self).__init__(FSM)
-
- def Enter(self):
- o = self.FSM.owner
- o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
- o.center_block("shutting down", o.h2, [0, 0, o.width,o.height - 20], o.light_grey)
- o.center_block("(unplug in 20s)", o.h2, [0, 10, o.width,o.height+10], o.light_grey)
- o.center_block("thank you for playing", o.h2, [0, 30, o.width,o.height+30], o.light_grey)
- o.update_display(0)
- command = 'bash -c "sleep 5; sudo shutdown -h now"&'
- os.system(command)
- pygame.quit()
- sys.exit()
- super(Shutdown, self).Enter()
-
- def Execute(self):
- pass
- #self.FSM.stateLife += 1
- #os.system('sudo shutdown -r now')
-
- def Exit(self):
- pass
-
- #====================================
- class SelTheme(State):
- def __init__(self,FSM):
- super(SelTheme, self).__init__(FSM)
-
- def Enter(self):
- o = self.FSM.owner
- o.header_text = "Select Theme"
- o.pub.register("beat", self)
- self.cur_el = 0
- self.globbed = glob.glob('/home/pi/zpc_ct/user/themes/*.thm')
- self.globbed.sort()
- self.names = [os.path.basename(x) for x in self.globbed]
- self.names = [os.path.splitext(x)[0] for x in self.names]
- if o.mconf['theme'] in self.names:
- _id = self.names.index(o.mconf['theme'])
- self.cur_el = _id
- #print('found theme ', _id)
- else:
- print('nope ', o.mconf['theme'], ' - ', self.globbed)
- #self.theme = ConfigObj("/home/pi/zpc_ct/themes/" + self.mconf['theme'])
- #print(os.path.splitext(x)[0])
- self.menu = self.names
-
- #self.cur_el = 0
- print('theme menu is ', self.menu)
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- draw_header(o)
- self.draw_main(o)
-
- o.update_display(0)
- super(SelTheme, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- menu1_actions(self, o)
- if o.keyState[16] == 1:
- draw_menu1(o)
- o.update_display(0)
- elif o.keyState[16] == 4:
- draw_header(o)
- self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
-
- if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
- draw_header(o)
- self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
- print('draw butt')
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- if o.keyState[0] == 1:
- if self.cur_el > 0:
- self.cur_el -= 1
- o.mconf['theme'] = self.menu[self.cur_el]
- o.save_config()
- o.load_config()
- o.apply_theme()
- print('cur el down is ', self.cur_el)
-
- #o.applyTheme
- if o.keyState[1] == 1:
- if self.cur_el < (len(self.menu) - 1):
- self.cur_el += 1
- o.mconf['theme'] = self.menu[self.cur_el]
- o.save_config()
- o.load_config()
- o.apply_theme()
- print('cur el up is ', self.cur_el)
- print('loading theme ', self.menu[self.cur_el], '-- ', o.mconf['theme'])
- if o.keyState[3] == 1:
- util_command(self, o, self.menu[self.cur_el])
-
- def draw_main(self, o):
- al = []
- ypos = 30
- if self.cur_el == 0:
- _iter = 0
- while len(al) < 4:
- al.append(self.menu[_iter])
- _iter += 1
- elif self.cur_el == 1:
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- al.append(self.menu[self.cur_el + 1])
- al.append(self.menu[self.cur_el + 2])
- elif self.cur_el == (len(self.menu) - 2):
- al.append(self.menu[self.cur_el - 2])
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- al.append(self.menu[self.cur_el + 1])
- elif self.cur_el == (len(self.menu) - 1):
- al.append(self.menu[self.cur_el - 3])
- al.append(self.menu[self.cur_el - 2])
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- else:
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- al.append(self.menu[self.cur_el + 1])
- al.append(self.menu[self.cur_el + 2])
- _iter = 0
- for i in al:
- if i == self.menu[self.cur_el]:
- #if _iter == self.cur_el:
- o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.light_grey)
- o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.blue)
- else:
- o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.blue)
- o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.light_grey)
- ypos += 20
- _iter += 1
-
- def draw_footer(self, o):
- _iter = 0
- width = o.width / 4
- xpos = 0
- yposa = 135 - 25
- yposb = 135
- opts = ["Up", "Down", "", ""]
- while _iter < 4:
- o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
-
- if o.keyState[_iter] == 1:
- o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
- o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
- else:
- o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
-
- xpos += width
- _iter += 1
-
-
- def ReceiveMessage(self, message):
- o = self.FSM.owner
- play_seq(o, message)
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
- #====================================
-
- class OpenSong(State):
- def __init__(self,FSM):
- super(OpenSong, self).__init__(FSM)
-
- def Enter(self):
- o = self.FSM.owner
- o.header_text = "Open Song"
- o.pub.register("beat", self)
- self.cur_el = 0
- self.globbed = glob.glob('/home/pi/zpc_ct/user/songs/*.sng')
- self.globbed.sort()
- if '/home/pi/zpc_ct/user/songs/_blank.sng' in self.globbed:
- self.globbed.remove('/home/pi/zpc_ct/user/songs/_blank.sng')
- #del self.globbed[0]
- self.names = [os.path.basename(x) for x in self.globbed]
- self.names = [os.path.splitext(x)[0] for x in self.names]
- print('we got these songs ', self.names)
- print('in these paths ', self.globbed)
- if o.mconf['default_song'] in self.names:
- _id = self.names.index(o.mconf['default_song'])
- self.cur_el = _id
- else:
- print('nope ', o.mconf['default_song'], ' - ', self.globbed)
- self.menu = self.names
-
- #self.cur_el = 0
- #print('theme menu is ', self.menu)
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- draw_header(o)
- self.draw_main(o)
-
- o.update_display(0)
- super(OpenSong, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- menu1_actions(self, o)
- if o.keyState[16] == 1:
- draw_menu1(o)
- o.update_display(0)
- elif o.keyState[16] == 4:
- draw_header(o)
- self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
-
- if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
- draw_header(o)
- self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
-
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- if o.keyState[0] == 1:
- if self.cur_el > 0:
- self.cur_el -= 1
- # o.mconf['theme'] = self.menu[self.cur_el]
- # o.save_config()
- # o.load_config()
- # o.apply_theme()
- print('cur el down is ', self.cur_el)
-
- #o.applyTheme
- if o.keyState[1] == 1:
- if self.cur_el < (len(self.menu) - 1):
- self.cur_el += 1
- # o.mconf['theme'] = self.menu[self.cur_el]
- # o.save_config()
- # o.load_config()
- # o.apply_theme()
- print('cur el up is ', self.cur_el)
- #print('loading theme ', self.menu[self.cur_el], '-- ', o.mconf['theme'])
- if o.keyState[3] == 1:
- #open_command(self, o, self.menu[self.cur_el])
- o.mconf['default_song'] = self.menu[self.cur_el]
- o.save_config()
- o.load_song()
- #pass
-
- def draw_main(self, o):
- al = []
- ypos = 30
- if self.cur_el == 0:
- _iter = 0
- while len(al) < 4:
- al.append(self.menu[_iter])
- _iter += 1
- elif self.cur_el == 1:
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- al.append(self.menu[self.cur_el + 1])
- al.append(self.menu[self.cur_el + 2])
- elif self.cur_el == (len(self.menu) - 2):
- al.append(self.menu[self.cur_el - 2])
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- al.append(self.menu[self.cur_el + 1])
- elif self.cur_el == (len(self.menu) - 1):
- al.append(self.menu[self.cur_el - 3])
- al.append(self.menu[self.cur_el - 2])
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- else:
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- al.append(self.menu[self.cur_el + 1])
- al.append(self.menu[self.cur_el + 2])
- _iter = 0
- for i in al:
- if i == self.menu[self.cur_el]:
- #if _iter == self.cur_el:
- o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.light_grey)
- o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.blue)
- else:
- o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.blue)
- o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.light_grey)
- ypos += 20
- _iter += 1
-
- def draw_footer(self, o):
- _iter = 0
- width = o.width / 4
- xpos = 0
- yposa = 135 - 25
- yposb = 135
- opts = ["Up", "Down", "Esc", "Open"]
- while _iter < 4:
- o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
-
- if o.keyState[_iter] == 1:
- o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
- o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
- else:
- o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
-
- xpos += width
- _iter += 1
-
-
- def ReceiveMessage(self, message):
- o = self.FSM.owner
- play_seq(o, message)
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
-
- class EnterText(State):
- def __init__(self,FSM):
- super(EnterText, self).__init__(FSM)
-
- def Enter(self):
- o = self.FSM.owner
-
- menu1_actions(self, o)
- if o.keyState[16] == 1:
- draw_menu1(o)
- o.update_display(0)
- elif o.keyState[16] == 4:
- draw_header(o)
- self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
- self.input_string = ""
- if o.sconf['title'] == 'blank':
-
- self.input_string += str(datetime.today().strftime('%Y%m%d'))
- else:
-
- self.input_string += o.sconf['title']
- #if
- o.header_text = "EnterText"
- o.pub.register("beat", self)
- self.last_action = pygame.time.get_ticks()
- self.caps = False
- self.cur_but = 18
- self.cur_letter = ""
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- pass
-
- self.skips = [7, 3, 11, 12, 13, 14, 15]
-
- self.lc_labels = [["p", "q", "r", "s"], ["t", "u", "v"], ["w", "x", "y", "z"], ["C", "A", "P", "S"],
- ["g", "h", "i"], ["j", "k", "l"], ["m", "n", "o"], ["D", "E", "L"],
- ["_", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-"], ["a", "b", "c"], ["d", "e", "f"], ["O", "K"],
- [], [], [], []]
-
- self.uc_labels = [["P", "Q", "R", "S"], ["T", "U", "V"], ["W", "X", "Y", "Z"], ["C", "A", "P", "S"],
- ["G", "H", "I"], ["J", "K", "L"], ["M", "N", "O"], ["D", "E", "L"],
- ["_", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-"], ["A", "B", "C"], ["D", "E", "F"], ["O", "K"],
- [], [], [], []]
-
- self.labels = self.lc_labels
-
- #self.songCycle = cycle(self.song)
- #self.curPattern = next(self.songCycle)
-
- self.cycles = []
- for l in self.labels:
- self.cycles.append(cycle(l))
-
-
-
- self.draw(o)
- o.update_display(0)
- super(EnterText, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- y_size = o.height / 4
- if o.keyState[11] == 1:
- if self.input_string != 'blank':
- o.title = self.input_string
- #o.bpm = o.sconf['bpm']
- o.sconf['title'] = self.input_string
-
- print('fsm saving')
- o.save_song()
- self.FSM.ToTransition('toFile')
- if o.keyState[16] > 0 and o.keyState[17] > 0:
- pass
- else:
- _iter = 0
- for k in o.keyState:
- if k == 1:
- cur_time = pygame.time.get_ticks()
- print(cur_time - self.last_action)
-
- #print('cur letter ', next(self.cycles[_iter]))
- if _iter not in self.skips:
- self.last_action = cur_time
- self.cur_letter = next(self.cycles[_iter])
- self.cur_but = _iter
- self.draw(o)
- o.center_block(self.input_string + self.cur_letter, o.h2, [0, 0, o.width, y_size], o.light_grey)
-
- if _iter == 7:
-
- self.input_string = self.input_string[:-1]
- #self.input_string = self.input_string.rstrip(self.input_string[-1])
- print('deleting')
- self.last_action = 100000000
- self.draw(o)
- o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
-
- elif _iter == 3:
- print('caps')
- if self.caps:
- self.caps = False
- self.labels = self.lc_labels
-
- else:
- self.caps = True
- self.labels = self.uc_labels
- self.draw(o)
- o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
- self.cycles = []
- for l in self.labels:
- self.cycles.append(cycle(l))
-
- o.update_display(0)
- _iter += 1
-
- cur_time = pygame.time.get_ticks()
- delay = cur_time - self.last_action
- if delay > 1000 and delay < 100000:
- self.input_string += self.cur_letter
- self.last_action = 100000000
- self.reset_cycles()
- self.draw(o)
-
- o.center_block(self.input_string, o.h2, [0, 0, o.width, y_size], o.light_grey)
- o.update_display(0)
-
- def ReceiveMessage(self, message):
- o = self.FSM.owner
- play_seq(o, message)
-
- def draw(self, o):
- x_size = o.width / 4
- y_size = o.height / 4
- og_x = 0
- o_x = og_x
- o_y = o.height
- text_padding = 6
-
- _id = 0
- while _id < 16:
- lab = ""
- for i in self.labels[_id]:
- lab += i
-
- if _id == 8:
- lab = "_12"
-
- o.draw.rectangle((o_x, o_y, o_x + x_size, o_y - y_size), outline=0, fill=o.blue)
- o.center_block(lab, o.h2, [o_x, o_y, o_x + x_size, o_y - y_size], o.light_grey)
-
- o_x = o_x + x_size
- _id += 1
- if _id % 4 == 0:
- o_y -= y_size
- o_x = og_x
- o.draw.rectangle((0, 0, o.width, y_size), outline=0, fill=o.blue)
-
- def reset_cycles(self):
- self.cycles = []
- for l in self.labels:
- self.cycles.append(cycle(l))
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
- #====================================
-
- class LoadSound(State):
- def __init__(self,FSM):
- super(LoadSound, self).__init__(FSM)
-
- def Enter(self):
- o = self.FSM.owner
- o.header_text = "Load Sound"
- o.pub.register("beat", self)
- self.cur_el = 0
-
- self.press_ticks_up = None
- self.press_ticks_down = None
-
- self.menu = []
-
- self.menu.append("..")
- self.menu += self.get_file_list(o)
- if o.last_load_sound_id != None and o.last_load_sound_id <= len(self.menu):
- self.cur_el = o.last_load_sound_id
- print('setting cur_el ', self.cur_el)
- self.last_preview = None
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- draw_header(o)
- self.draw_main(o)
-
- o.update_display(0)
- super(LoadSound, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- menu1_actions(self, o)
- if o.keyState[16] == 1:
- draw_menu1(o)
- o.update_display(0)
- elif o.keyState[16] == 4:
- draw_header(o)
- self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
-
- if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
- draw_header(o)
- self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
- #print('draw butt')
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
-
- since_up = 0
- if o.keyState[0] == 2:
- if self.press_ticks_up == None:
- self.press_ticks_up = pygame.time.get_ticks()
- since_up = pygame.time.get_ticks() - self.press_ticks_up
- else:
- self.press_ticks_up = None
-
- self.press_ticks_up = pygame.time.get_ticks()
-
-
- if o.keyState[0] == 1 or since_up > 250:
- if self.cur_el > 0:
- self.cur_el -= 1
- self.draw_main(o)
- o.update_display(0)
- self.press_ticks_up = pygame.time.get_ticks()
-
-
-
- since_down = 0
- if o.keyState[1] == 2:
- if self.press_ticks_down == None:
- self.press_ticks_down = pygame.time.get_ticks()
- since_down = pygame.time.get_ticks() - self.press_ticks_down
- else:
- self.press_ticks_down = None
-
- self.press_ticks_down = pygame.time.get_ticks()
-
-
- if o.keyState[1] == 1 or since_down > 250:
- if self.cur_el < (len(self.menu) - 1):
- self.cur_el += 1
- self.draw_main(o)
- o.update_display(0)
- self.press_ticks_down = pygame.time.get_ticks()
-
-
-
-
- if o.keyState[2] == 1:
- if self.is_wav():
- if self.last_preview == self.menu[self.cur_el]:
- pass
- else:
- snd = pygame.mixer.Sound(o.load_song_dir + self.menu[self.cur_el])
- pygame.mixer.Sound.play(snd)
- #o.last_load_sound_id = self.cur_el
-
-
- if o.keyState[3] == 1:
- if self.menu[self.cur_el] == '..':
- print('directory up')
- o.last_load_sound_id = None
- if o.load_song_dir == '/home/pi/zpc_ct/user/sounds/':
- print('root dir - cant go up')
- else:
- o.load_song_dir = os.path.dirname(os.path.dirname(o.load_song_dir))
- o.load_song_dir += '/'
- print('new up dir is ', o.load_song_dir)
- self.menu = []
- self.menu.append("..")
- self.menu += self.get_file_list(o)
-
- self.cur_el = 0
-
- elif os.path.isdir(o.load_song_dir + self.menu[self.cur_el]):
- print('this is a directory ', o.load_song_dir + self.menu[self.cur_el])
- o.load_song_dir = o.load_song_dir + self.menu[self.cur_el] + '/'
- self.menu = []
- self.menu.append("..")
- self.menu += self.get_file_list(o)
- self.cur_el = 0
-
- else:
- print('this is not a directory ', o.load_song_dir + self.menu[self.cur_el])
- o.soundSlots[o.eSound].file = o.load_song_dir + self.menu[self.cur_el]
- o.soundSlots[o.eSound].volume = 16
- o.soundSlots[o.eSound].pitch = 0
- o.soundSlots[o.eSound].create_sound()
- o.soundSlots[o.eSound].set_pitch()
- o.last_load_sound_id = self.cur_el
- self.FSM.ToTransition('toMain')
-
- def get_file_list(self, o):
- dirs = os.listdir(o.load_song_dir)
- dirs.sort()
-
- return dirs
-
- def draw_main(self, o):
- al = []
- ypos = 30
- #print(self.menu)
- if self.cur_el == 0:
- _iter = 0
- while len(al) < 4:
- if _iter < len(self.menu):
- #print('appending to al', _iter, ' ', len(self.menu))
- al.append(self.menu[_iter])
- else:
- break
- _iter += 1
- elif self.cur_el == 1:
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- if (self.cur_el + 1) < len(self.menu):
- al.append(self.menu[self.cur_el + 1])
- if (self.cur_el + 2) < len(self.menu):
- al.append(self.menu[self.cur_el + 2])
- elif self.cur_el == (len(self.menu) - 2):
- al.append(self.menu[self.cur_el - 2])
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- al.append(self.menu[self.cur_el + 1])
- elif self.cur_el == (len(self.menu) - 1):
- al.append(self.menu[self.cur_el - 3])
- al.append(self.menu[self.cur_el - 2])
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- else:
- al.append(self.menu[self.cur_el - 1])
- al.append(self.menu[self.cur_el])
- al.append(self.menu[self.cur_el + 1])
- al.append(self.menu[self.cur_el + 2])
- _iter = 0
- #print(al)
- for i in al:
- if i == self.menu[self.cur_el]:
- #if _iter == self.cur_el:
- o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.light_grey)
- o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.blue)
- else:
- o.draw.rectangle((0, ypos, o.width, ypos + 20), outline=0, fill=o.blue)
- o.center_block(i, o.h2, [0, ypos, o.width,ypos + 20], o.light_grey)
- ypos += 20
- _iter += 1
-
- def draw_footer(self, o):
- _iter = 0
- width = o.width / 4
- xpos = 0
- yposa = 135 - 25
- yposb = 135
- opts = ["Up", "Down", "Play", "Open"]
- while _iter < 4:
- o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.blue)
-
- if o.keyState[_iter] == 1:
- o.draw.rectangle((xpos, yposa, xpos + width, yposb), outline=0, fill=o.light_grey)
- o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.blue)
- else:
- if _iter == 2:
- if self.is_wav():
- o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
- else:
- o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.dark_grey)
- else:
- o.center_block(opts[_iter], o.h2, [xpos,yposa,xpos + width,yposb], o.light_grey)
-
- xpos += width
- _iter += 1
-
- def is_wav(self):
- if len(self.menu[self.cur_el]) > 3 and (self.menu[self.cur_el][-1] == 'V' or self.menu[self.cur_el][-1] == 'v') and (self.menu[self.cur_el][-2] == 'A' or self.menu[self.cur_el][-2] == 'a'):
- return True
- else:
- return False
-
- def ReceiveMessage(self, message):
- o = self.FSM.owner
- play_seq(o, message)
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
- #====================================
-
- class Ping(State):
- def __init__(self,FSM):
- super(Ping, self).__init__(FSM)
-
- def Enter(self):
- o = self.FSM.owner
-
- o.header_text = "Ping"
- o.pub.register("beat", self)
-
- #o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
- #o.center_block("ping", o.h2, [0, 0, o.width,o.height], o.light_grey)
- #o.update_display(0)
-
-
-
-
- self.pinging = self.check_ping()
-
- self.draw_main(o)
-
- draw_header(o)
- o.update_display(0)
- super(Ping, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- menu1_actions(self, o)
- if o.keyState[16] == 1:
- draw_menu1(o)
- o.update_display(0)
- elif o.keyState[16] == 4:
- draw_header(o)
- #self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
-
- if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
- draw_header(o)
- #self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
-
-
- def draw_main(self, o):
- o.center_block(self.pinging, o.h2, [0, 0, o.width, o.height], o.light_grey)
-
- def check_ping(self):
- hostname = "8.8.8.8"
- response = os.system("ping -c 1 " + hostname)
- # and then check the response...
- if response == 0:
- pingstatus = "Network Active "
- else:
- pingstatus = "Network Error "
-
- return pingstatus
-
- def ReceiveMessage(self, message):
- o = self.FSM.owner
- play_seq(o, message)
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
- #====================================
-
-
- class Wifi(State):
- def __init__(self,FSM):
- super(Wifi, self).__init__(FSM)
-
- def Enter(self):
- o = self.FSM.owner
-
- o.header_text = "Wifi"
- o.pub.register("beat", self)
-
- self.ipad = self.extract_ip()
- self.ssid = os.popen("sudo iwgetid -r").read()
- o.center_block(self.ipad, o.h2, [0, 0, o.width,o.height], o.light_grey)
-
- draw_header(o)
- self.draw_main(o)
- o.update_display(0)
- super(Wifi, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- menu1_actions(self, o)
- if o.keyState[16] == 1:
- draw_menu1(o)
- o.update_display(0)
- elif o.keyState[16] == 4:
- draw_header(o)
- #self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
-
- if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
- draw_header(o)
- #self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
-
-
- def draw_main(self, o):
- o.center_block(self.ipad, o.h2, [0, 0, o.width, o.height], o.light_grey)
- o.center_block(self.ssid, o.h2, [0, 40, o.width, o.height+40], o.light_grey)
-
-
- def extract_ip(self):
- st = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- try:
- #st.connect(('10.255.255.255', 1))
- st.connect(("8.8.8.8", 80))
- IP = st.getsockname()[0]
- except Exception:
- IP = '127.0.0.1'
- finally:
- st.close()
- return IP
- #print(extract_ip())
-
- def ReceiveMessage(self, message):
- o = self.FSM.owner
- play_seq(o, message)
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
- #====================================
-
-
-
- class Defender(State):
- def __init__(self,FSM):
- super(Defender, self).__init__(FSM)
-
- def Enter(self):
- self.ball_size = 10
- self.ballx = self.ball_size
- self.bally = self.ball_size
-
- self.ball_speed = 8
- self.ball_x_dir = 1
- self.ball_y_dir = 1
-
- self.ball2x = self.ball_size + 180
- self.ball2y = self.ball_size + 70
-
- self.ball2_x_dir = -1
- self.ball2_y_dir = -1
-
- self.xmult = 1.0
-
- o = self.FSM.owner
- o.header_text = "Balls"
- o.pub.register("beat", self)
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- draw_header(o)
- o.update_display(0)
- super(Defender, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- menu1_actions(self, o)
- if o.keyState[16] == 1:
- draw_menu1(o)
- o.update_display(0)
-
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- now = datetime.now()
- current_time = time.strftime("%-I:%M %p")
-
-
- if self.ballx < (0 + self.ball_size):
- self.ball_x_dir = 1
- if self.ballx > (o.width - self.ball_size):
- self.ball_x_dir = -1
-
- if self.bally < (0 + self.ball_size):
- self.ball_y_dir = 1
- if self.bally > (o.height - self.ball_size):
- self.ball_y_dir = -1
-
- # if self.ballx > (o.width - self.ball_size) or self.ballx < (0 + self.ball_size):
- # self.ball_x_dir *= -1
- # if self.bally > (o.height - self.ball_size) or self.bally < (0 + self.ball_size):
- # self.ball_y_dir *= -1
-
- self.ballx += self.ball_speed * self.ball_x_dir
- self.bally += self.ball_speed * self.ball_y_dir
-
-
- if self.ball2x < (0 + self.ball_size):
- self.ball2_x_dir = 1
- self.xmult = random.uniform(.6, 1.2)
- if self.ball2x > (o.width - self.ball_size):
- self.ball2_x_dir = -1
- self.xmult = random.uniform(.6, 1.2)
-
- if self.ball2y < (0 + self.ball_size):
- self.ball2_y_dir = 1
- if self.ball2y > (o.height - self.ball_size):
- self.ball2_y_dir = -1
-
-
- # if self.ball2x > (o.width - self.ball_size) or self.ball2x < (0 + self.ball_size):
- # self.ball2_x_dir *= -1
- # self.xmult = random.uniform(.8, 1.2)
- # if self.ball2y > (o.height - self.ball_size) or self.ball2y < (0 + self.ball_size):
- # self.ball2_y_dir *= -1
-
- self.ball2x += (self.ball_speed * self.ball2_x_dir) * self.xmult
- self.ball2y += (self.ball_speed * self.ball2_y_dir)
-
- o.draw.rectangle((0, 0, o.width, o.height), outline=0, fill=o.blue)
-
- o.draw.ellipse((self.ballx - self.ball_size, self.bally - self.ball_size, self.ballx + self.ball_size, self.bally + self.ball_size), fill = o.light_grey, outline =o.light_grey)
- o.draw.ellipse((self.ball2x - self.ball_size, self.ball2y - self.ball_size, self.ball2x + self.ball_size, self.ball2y + self.ball_size), fill = o.light_grey, outline =o.light_grey)
- #o.center_block(current_time, o.h3, [0,0,o.width,o.height], o.pink)
- o.update_display(0)
-
- def ReceiveMessage(self, message):
- o = self.FSM.owner
- play_seq(o, message)
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
- #====================================
- #====================================
-
-
-
- class Update(State):
- def __init__(self,FSM):
- super(Update, self).__init__(FSM)
-
- def Enter(self):
-
- o = self.FSM.owner
- o.header_text = "Update"
- o.pub.register("beat", self)
- g = git.cmd.Git("/home/pi/zpc_ct/")
- self.msg = g.pull()
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- draw_header(o)
- o.update_display(0)
- super(Update, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- menu1_actions(self, o)
- if o.keyState[16] == 1:
- draw_menu1(o)
- o.update_display(0)
- elif o.keyState[16] == 4:
- draw_header(o)
- #self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
-
- if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
- draw_header(o)
- #self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
-
- if o.keyState[16] > 0 or o.keyState[17] > 0:
- pass
- else:
- pass
- #o.update_display(0)
-
- def draw_main(self, o):
- #o.center_text(self.msg, o.h1, o.width, 25, o.light_grey)
- o.center_block(self.msg, o.h2, [0, 0, o.width, o.height], o.light_grey)
-
- def ReceiveMessage(self, message):
- o = self.FSM.owner
- play_seq(o, message)
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
- #====================================
|