desktop.js 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771
  1. // SPDX-FileCopyrightText: 2012-2023 MOD Audio UG
  2. // SPDX-License-Identifier: AGPL-3.0-or-later
  3. function Desktop(elements) {
  4. var self = this
  5. // The elements below are expected to be all defined in HTML and passed as parameter
  6. elements = $.extend({
  7. titleBox: $('<div>'),
  8. performanceTitleBox: $('<div>'),
  9. zoomIn: $('<div>'),
  10. zoomOut: $('<div>'),
  11. addMidiButton: $('<div>'),
  12. midiPortsWindow: $('<div>'),
  13. midiPortsList: $('<div>'),
  14. pedalPresetsWindow: $('<div>'),
  15. pedalPresetsList: $('<div>'),
  16. pedalPresetsOverlay: $('<div>'),
  17. updateDeviceWindow: $('<div>'),
  18. saveBox: $('<div>'),
  19. saveButton: $('<div>'),
  20. saveAsButton: $('<div>'),
  21. resetButton: $('<div>'),
  22. cvAddressingButton: $('<div>'),
  23. snapshotSaveButton: $('<div>'),
  24. snapshotSaveAsButton: $('<div>'),
  25. snapshotManageButton: $('<div>'),
  26. transportButton: $('<div>'),
  27. transportWindow: $('<div>'),
  28. transportPlay: $('<div>'),
  29. transportBPB: $('<div>'),
  30. transportBPM: $('<div>'),
  31. transportSyncMode: $('<div>'),
  32. effectBox: $('<div>'),
  33. effectBoxTrigger: $('<div>'),
  34. cloudPluginBox: $('<div>'),
  35. cloudPluginBoxTrigger: $('<div>'),
  36. pedalboardTrigger: $('<div>'),
  37. fileManagerBox: $('<div>'),
  38. fileManagerBoxTrigger: $('<div>'),
  39. performanceBox: $('<div>'),
  40. performanceBoxTrigger: $('<div>'),
  41. pedalboardBox: $('<div>'),
  42. pedalboardBoxTrigger: $('<div>'),
  43. bankBox: $('<div>'),
  44. bankBoxTrigger: $('<div>'),
  45. bankList: $('<div>'),
  46. bankPedalboardList: $('<div>'),
  47. bankSearchResult: $('<div>'),
  48. shareButton: $('<div>'),
  49. shareWindow: $('<div>'),
  50. inputBox: $('<div>'),
  51. presetSaveBox: $('<div>'),
  52. devicesIcon: $('<div>'),
  53. devicesWindow: $('<div>'),
  54. statusIcon: $('<div>'),
  55. settingsIcon: $('<div>'),
  56. upgradeIcon: $('<div>'),
  57. upgradeWindow: $('<div>'),
  58. bypassLeftButton: $('<div>'),
  59. bypassRightButton: $('<div>'),
  60. bufferSizeButton: $('<div>'),
  61. xrunsButton: $('<div>'),
  62. cpuStatsButton: $('<div>'),
  63. cpuButton: $('<div>'),
  64. cpuLoadWindow: $('<div>'),
  65. cpuLoadList: $('<div>'),
  66. cpuLoadSummary: $('<div>'),
  67. }, elements)
  68. this.installationQueue = new InstallationQueue()
  69. this.windowManager = new WindowManager()
  70. this.pluginIndexer = lunr(function () {
  71. this.field('data')
  72. this.ref('id')
  73. this.requireAllTerms = true
  74. })
  75. this.pedalboardIndexer = lunr(function () {
  76. this.field('data')
  77. this.ref('id')
  78. this.requireAllTerms = true
  79. })
  80. this.pluginIndexerData = {}
  81. this.pedalboardIndexerData = {}
  82. this.previousPedalboardList = null
  83. this.cvAddressing = false
  84. this.resetPluginIndexer = function (plugins) {
  85. self.pluginIndexer = lunr(function () {
  86. this.field('data')
  87. this.ref('id')
  88. this.requireAllTerms = true
  89. })
  90. var i, plugin
  91. for (i in plugins) {
  92. plugin = plugins[i]
  93. self.pluginIndexer.add({
  94. id: plugin.uri,
  95. data: [plugin.uri, plugin.name, plugin.brand, plugin.comment, plugin.category.join(" ")].join(" "),
  96. })
  97. }
  98. self.pluginIndexerData = plugins
  99. }
  100. this.pedalboardStatsSuccess = false;
  101. this.pedalboardStats = {};
  102. this.resetPedalboardStats = function() {
  103. this.pedalboardStatsSuccess = false;
  104. if (! CLOUD_TERMS_ACCEPTED) {
  105. return
  106. }
  107. $.ajax({
  108. url: SITEURL + '/pedalboards/stats',
  109. type: 'GET',
  110. success: function(stats) {
  111. self.pedalboardStatsSuccess = true;
  112. self.pedalboardStats = stats;
  113. },
  114. cache: false
  115. })
  116. };
  117. this.getPedalboardHref = function(uri, unstable) {
  118. if (!this.pedalboardStatsSuccess) {
  119. return null;
  120. }
  121. var base64Uri = btoa(uri);
  122. if (!this.pedalboardStats[base64Uri]) {
  123. return null;
  124. }
  125. var encodedUri = encodeURIComponent(uri);
  126. if (unstable) {
  127. encodedUri += '&unstable=true';
  128. }
  129. return PEDALBOARDS_URL + '/?plugin_uri=' + encodedUri;
  130. };
  131. this.midiDevices = new MidiPortsWindow({
  132. midiPortsWindow: elements.midiPortsWindow,
  133. midiPortsList: elements.midiPortsList,
  134. })
  135. this.hardwareManager = new HardwareManager({
  136. address: function (instanceAndSymbol, addressing, callback) {
  137. $.ajax({
  138. url: '/effect/parameter/address/' + instanceAndSymbol,
  139. type: 'POST',
  140. data: JSON.stringify(addressing),
  141. success: function (resp) {
  142. if (resp) {
  143. self.setPedalboardAsModified(true)
  144. callback(true)
  145. } else {
  146. new Bug("Couldn't address parameter, not allowed")
  147. callback(false)
  148. }
  149. },
  150. error: function () {
  151. new Bug("Couldn't address parameter, server error")
  152. callback(false)
  153. },
  154. cache: false,
  155. dataType: 'json'
  156. })
  157. },
  158. setEnabled: function (instance, portSymbol, enabled, feedback, forceAddress, momentaryMode) {
  159. if (!enabled && feedback === undefined) {
  160. console.warn("ERROR setEnabled called as false, but with undefined feedback")
  161. feedback = true
  162. }
  163. if (instance == "/pedalboard") {
  164. self.transportControls.setControlEnabled(portSymbol, enabled, feedback, forceAddress, momentaryMode)
  165. return
  166. }
  167. self.pedalboard.pedalboard('setPortEnabled', instance, portSymbol, enabled, feedback, forceAddress, momentaryMode)
  168. },
  169. renderForm: function (instance, port) {
  170. var label
  171. if (instance == "/pedalboard") {
  172. label = "Pedalboard"
  173. } else {
  174. label = self.pedalboard.pedalboard('getLabel', instance)
  175. }
  176. if (port.symbol == ':bypass' || port.symbol == ':presets') {
  177. context = {
  178. label: label,
  179. name: port.symbol == ':bypass' ? "On/Off" : port.name
  180. }
  181. return Mustache.render(TEMPLATES.bypass_addressing, context)
  182. }
  183. context = {
  184. label: label,
  185. name: port.shortName
  186. }
  187. return Mustache.render(TEMPLATES.addressing, context)
  188. },
  189. isApp: function() {
  190. return self.isApp;
  191. },
  192. })
  193. this.pedalPresets = new SnapshotsManager({
  194. pedalPresetsWindow: elements.pedalPresetsWindow,
  195. pedalPresetsList: elements.pedalPresetsList,
  196. pedalPresetsOverlay: elements.pedalPresetsOverlay,
  197. hardwareManager: self.hardwareManager,
  198. renamedCallback: function (name) {
  199. const newTitle = (self.title || 'Untitled') + " - " + (name || 'Default')
  200. self.titleBox.text(newTitle)
  201. self.performanceTitleBox.text(newTitle)
  202. }
  203. })
  204. this.isApp = false
  205. this.title = ''
  206. this.cloudAccessToken = null
  207. this.cloudHardwareDeviceVersions = null
  208. this.pedalboardBundle = null
  209. this.pedalboardEmpty = true
  210. this.pedalboardModified = false
  211. this.pedalboardPresetId = 0
  212. this.pedalboardPresetName = ''
  213. this.pedalboardDemoPluginsNotified = false
  214. this.loadingPeldaboardForFirstTime = true
  215. this.licenseManager = null
  216. this.pedalboard = self.makePedalboard(elements.pedalboard, elements.effectBox)
  217. elements.zoomIn.click(function () {
  218. self.pedalboard.pedalboard('zoomIn')
  219. })
  220. elements.zoomOut.click(function () {
  221. self.pedalboard.pedalboard('zoomOut')
  222. })
  223. var ajaxFactory = function (url, errorMessage) {
  224. return function (callback) {
  225. $.ajax({
  226. url: url,
  227. success: callback,
  228. error: function () {
  229. new Error(errorMessage)
  230. },
  231. cache: false,
  232. dataType: 'json'
  233. })
  234. }
  235. }
  236. elements.pedalboardTrigger.click(function () {
  237. self.windowManager.closeWindows(null, true)
  238. })
  239. this.titleBox = elements.titleBox
  240. this.performanceTitleBox = elements.performanceTitleBox
  241. this.ParameterSet = function (paramchange) {
  242. $.ajax({
  243. url: '/effect/parameter/set/' ,
  244. type: 'POST',
  245. contentType: 'application/json',
  246. data: JSON.stringify(paramchange),
  247. success: function (resp) {
  248. if (!resp) {
  249. new Bug("Couldn't address parameter, not allowed")
  250. }
  251. },
  252. error: function () {
  253. new Bug ("Couldn't address parameter, server error")
  254. },
  255. cache: false,
  256. global: false,
  257. dataType: 'json'
  258. })
  259. }
  260. this.cloudPluginListFunction = function (callback) {
  261. $.ajax({
  262. method: 'GET',
  263. url: '/effect/list',
  264. success: callback,
  265. cache: false,
  266. dataType: 'json',
  267. })
  268. }
  269. this.cloudPluginSearchFunction = function (query, callback) {
  270. $.ajax({
  271. method: 'GET',
  272. url: '/effect/search',
  273. query: query,
  274. success: callback,
  275. cache: false,
  276. dataType: 'json'
  277. })
  278. }
  279. this.pedalboardListFunction = function (callback) {
  280. if (self.previousPedalboardList != null && callback) {
  281. callback(self.previousPedalboardList)
  282. return
  283. }
  284. $.ajax({
  285. method: 'GET',
  286. url: '/pedalboard/list',
  287. success: function(pedals) {
  288. var allpedals = {}
  289. for (var i=0; i<pedals.length; i++) {
  290. var pedal = pedals[i]
  291. allpedals[pedal.bundle] = pedal
  292. self.pedalboardIndexer.add({
  293. id: pedal.bundle,
  294. data: pedal.title
  295. })
  296. }
  297. self.pedalboardIndexerData = allpedals
  298. self.previousPedalboardList = pedals
  299. if (callback) {
  300. callback(pedals)
  301. }
  302. },
  303. cache: false,
  304. dataType: 'json'
  305. })
  306. }
  307. this.pedalboardSearchFunction = function (local, query, callback) {
  308. if (local)
  309. {
  310. var allpedals = self.pedalboardIndexerData
  311. var pedals = []
  312. ret = self.pedalboardIndexer.search(query)
  313. for (var i in ret) {
  314. var uri = ret[i].ref
  315. pedals.push(allpedals[uri])
  316. }
  317. callback(pedals, '')
  318. }
  319. else if (CLOUD_TERMS_ACCEPTED)
  320. {
  321. // NOTE: this part is never called. pedalboard search is always local
  322. $.ajax({
  323. method: 'GET',
  324. url: SITEURL + '/pedalboard/search/?term=' + escape(query),
  325. success: function (pedals) {
  326. callback(pedalboards, SITEURL)
  327. },
  328. cache: false,
  329. dataType: 'json'
  330. })
  331. }
  332. }
  333. this.blockUI = function (isUpdating) {
  334. if ($('body').find('.screen-disconnected').length != 0) {
  335. return
  336. }
  337. var block = $('<div class="screen-disconnected blocker">')
  338. if (isUpdating) {
  339. block.html('<p>Auto-update in progress, please wait...</p>')
  340. } else {
  341. block.html('<p>Disconnected</p>')
  342. var re = $("<div class='button icon'>Reload</div>").appendTo(block);
  343. re.css("background-image", "url(img/icons/25/reload.png)");
  344. re.click(function () { location.reload(); });
  345. }
  346. $('body').append(block).css('overflow', 'hidden')
  347. $('#wrapper').css('z-index', -1)
  348. $('#plugins-library').css('z-index', -1)
  349. $('#cloud-plugins-library').css('z-index', -1)
  350. $('#performance').css('z-index', -1)
  351. $('#pedalboards-library').css('z-index', -1)
  352. $('#bank-library').css('z-index', -1)
  353. $('#main-menu').css('z-index', -1)
  354. ws.close()
  355. }
  356. this.init = function () {
  357. $(".mod-init-hidden").removeClass("mod-init-hidden");
  358. $("body").addClass("initialized");
  359. }
  360. this.authenticateDevice = function (callback) {
  361. $.ajax({
  362. method: 'GET',
  363. url: SITEURL + '/devices/nonce',
  364. cache: false,
  365. success: function (resp) {
  366. if (!resp || !resp.nonce) {
  367. callback(false)
  368. return
  369. }
  370. $.ajax({
  371. url: '/auth/nonce',
  372. type: 'POST',
  373. cache: false,
  374. contentType: 'application/json',
  375. dataType: 'json',
  376. data: JSON.stringify(resp),
  377. success: function (resp) {
  378. if (!resp || !resp.message) {
  379. //$('#mod-cloud-plugins').hide()
  380. callback(false)
  381. console.log("Webserver does not support MOD tokens, downloads will not be possible")
  382. return;
  383. }
  384. $.ajax({
  385. url: SITEURL + '/devices/tokens',
  386. type: 'POST',
  387. cache: false,
  388. contentType: 'application/json',
  389. dataType: 'json',
  390. data: JSON.stringify(resp),
  391. success: function (resp) {
  392. if (!resp || !resp.message) {
  393. callback(false)
  394. return;
  395. }
  396. var license_info = resp.license_info;
  397. if (resp['upgrade']) {
  398. $.ajax({
  399. method: 'GET',
  400. url: resp['image-href'],
  401. cache: false,
  402. contentType: 'application/json',
  403. success: function (data) {
  404. elements.upgradeWindow.upgradeWindow('setup', resp['upgrade-required'], data)
  405. },
  406. error: function () {
  407. elements.upgradeWindow.upgradeWindow('setErrored')
  408. },
  409. })
  410. } else {
  411. elements.upgradeWindow.upgradeWindow('setUpdated')
  412. }
  413. $.ajax({
  414. url: '/auth/token',
  415. type: 'POST',
  416. cache: false,
  417. contentType: 'application/json',
  418. dataType: 'json',
  419. data: JSON.stringify(resp),
  420. success: function (resp) {
  421. self.cloudAccessToken = resp.access_token;
  422. var opts = {
  423. from_args: {
  424. headers: { 'Authorization' : 'MOD ' + resp.access_token }
  425. }
  426. }
  427. if (self.licenseManager === null) {
  428. self.licenseManager = new LicenseManager()
  429. self.licenseManager.addLicenses(license_info, function(installed) {
  430. if (installed > 0) {
  431. var s = installed > 1 ? 's' : ''
  432. new Notification('info', installed + ' plugin'+s+' licensed')
  433. }
  434. })
  435. }
  436. callback(true, opts);
  437. },
  438. error: function () {
  439. callback(false);
  440. },
  441. })
  442. },
  443. error: function () {
  444. callback(false)
  445. },
  446. })
  447. },
  448. error: function () {
  449. callback(false)
  450. },
  451. })
  452. },
  453. error: function () {
  454. callback(false)
  455. },
  456. })
  457. }
  458. this.setPedalboardAsModified = function (modified) {
  459. this.pedalboardModified = modified
  460. if (modified) {
  461. elements.saveButton.addClass('unmodified-changes')
  462. } else {
  463. elements.saveButton.removeClass('unmodified-changes')
  464. }
  465. }
  466. elements.devicesIcon.statusTooltip()
  467. this.ccDeviceManager = new ControlChainDeviceManager({
  468. devicesIcon: elements.devicesIcon,
  469. devicesWindow: elements.devicesWindow,
  470. updateInfoWindow: elements.updateDeviceWindow,
  471. setIconTooltip: function (msg) {
  472. elements.devicesIcon.statusTooltip('message', msg, true)
  473. },
  474. showNotification: function (msg) {
  475. if (! self.loadingPeldaboardForFirstTime) {
  476. new Notification('info', msg, 5000)
  477. }
  478. },
  479. cancelDownload: function (callback) {
  480. $.ajax({
  481. url: '/controlchain/cancel/',
  482. type: 'POST',
  483. success: function () {
  484. callback()
  485. },
  486. error: function () {
  487. callback()
  488. },
  489. cache: false,
  490. dataType: 'json'
  491. })
  492. },
  493. })
  494. this.ccDeviceAdded = function (dev_uri, label, labelsuffix, version) {
  495. self.ccDeviceManager.deviceAdded(dev_uri, label+labelsuffix, version)
  496. self.checkHardwareDeviceVersion(dev_uri, label, version)
  497. }
  498. this.ccDeviceRemoved = function (dev_uri, label, version) {
  499. self.ccDeviceManager.deviceRemoved(dev_uri, label, version)
  500. elements.upgradeWindow.upgradeWindow('cancelDeviceSetup', dev_uri)
  501. }
  502. this.ccDeviceUpdateFinished = function () {
  503. elements.upgradeWindow.upgradeWindow('setUpdated')
  504. elements.upgradeWindow.hide()
  505. self.ccDeviceManager.hideUpdateWindow()
  506. new Notification("info", "Control Chain device firmware update complete!")
  507. }
  508. this.cpuLoadPanel = new CpuLoadPanel({
  509. window: elements.cpuLoadWindow,
  510. list: elements.cpuLoadList,
  511. summary: elements.cpuLoadSummary,
  512. pedalboard: elements.pedalboard,
  513. })
  514. this.transportControls = new TransportControls({
  515. transportButton: elements.transportButton,
  516. transportWindow: elements.transportWindow,
  517. transportPlay: elements.transportPlay,
  518. transportBPB: elements.transportBPB,
  519. transportBPM: elements.transportBPM,
  520. transportSyncMode: elements.transportSyncMode,
  521. openAddressingDialog: function (port, label) {
  522. self.hardwareManager.open("/pedalboard", port, label)
  523. },
  524. setNewBeatsPerMinuteValue: function (bpm) {
  525. self.hardwareManager.setBeatsPerMinuteValue(bpm)
  526. },
  527. removeBPMHardwareMapping: function(syncMode) {
  528. var instanceAndSymbol = "/pedalboard/:bpm"
  529. if (self.hardwareManager.removeHardwareMappping(instanceAndSymbol)) {
  530. var source = syncMode === "link" ? "Ableton Link" : "MIDI"
  531. new Notification('info', 'BPM addressing removed, incompatible with ' + source + ' sync mode', 8000)
  532. }
  533. self.setPedalboardAsModified(true)
  534. },
  535. setSyncMode: function(syncMode, callback) {
  536. $.ajax({
  537. url: '/pedalboard/transport/set_sync_mode/' + syncMode,
  538. type: 'POST',
  539. success: function (resp) {
  540. if (resp) {
  541. callback(true)
  542. } else {
  543. new Bug("Couldn't set new sync mode")
  544. callback(false)
  545. }
  546. },
  547. error: function () {
  548. new Bug("Couldn't set new sync mode, server error")
  549. callback(false)
  550. },
  551. cache: false,
  552. dataType: 'json'
  553. })
  554. },
  555. unaddressPort: function (portSymbol, syncMode, callback) {
  556. var addressing = {
  557. uri : kNullAddressURI,
  558. label : "",
  559. minimum: 0,
  560. maximum: 0,
  561. value : 0,
  562. steps : 0,
  563. }
  564. var instanceAndSymbol = "/pedalboard/" + portSymbol
  565. $.ajax({
  566. url: '/effect/parameter/address/' + instanceAndSymbol,
  567. type: 'POST',
  568. data: JSON.stringify(addressing),
  569. success: function (resp) {
  570. if (resp) {
  571. if (self.hardwareManager.removeHardwareMappping(instanceAndSymbol)) {
  572. var source = syncMode === "link" ? "Ableton Link" : "MIDI"
  573. new Notification('info', 'BPM addressing removed, incompatible with ' + source + ' sync mode', 8000)
  574. }
  575. self.setPedalboardAsModified(true)
  576. callback(true)
  577. } else {
  578. new Bug("Couldn't address parameter")
  579. callback(false)
  580. }
  581. },
  582. error: function () {
  583. new Bug("Couldn't address parameter, server error")
  584. callback(false)
  585. },
  586. cache: false,
  587. dataType: 'json'
  588. })
  589. },
  590. })
  591. this.checkHardwareDeviceVersion = function (dev_uri, label, version) {
  592. if (self.cloudAccessToken == null) {
  593. self.authenticateDevice(function (ok) {
  594. if (ok && self.cloudAccessToken != null) {
  595. self.checkHardwareDeviceVersion(dev_uri, label, version)
  596. } else {
  597. console.log("Notice: failed to check device version")
  598. }
  599. })
  600. return
  601. }
  602. if (self.cloudHardwareDeviceVersions == null) {
  603. $.ajax({
  604. method: 'GET',
  605. url: CONTROLCHAIN_URL + '/versions',
  606. success: function (resp) {
  607. if (!resp) {
  608. console.log("Notice: failed to get latest device version")
  609. return
  610. }
  611. if (resp.api_version != 1) {
  612. return
  613. }
  614. self.cloudHardwareDeviceVersions = resp
  615. self.checkHardwareDeviceVersion(dev_uri, label, version)
  616. },
  617. error: function (resp) {
  618. console.log("Notice: failed to get latest device version")
  619. },
  620. cache: false,
  621. dataType: 'json'
  622. })
  623. return
  624. }
  625. var devs = self.cloudHardwareDeviceVersions.devices
  626. if (! devs || Object.keys(devs).length == 0) {
  627. return
  628. }
  629. var dev = devs[dev_uri]
  630. if (! dev) {
  631. return
  632. }
  633. var majminor = VERSION.split(".").slice(0, 2).join(".")
  634. var cloudversion = dev[majminor]
  635. if (! cloudversion) {
  636. cloudversion = dev["latest"]
  637. if (! cloudversion) {
  638. return
  639. }
  640. }
  641. if (compareVersions(version.split("."), cloudversion.split("."), 3) < 0) {
  642. data = {
  643. 'uri': dev_uri,
  644. 'label': label,
  645. 'download-url': CONTROLCHAIN_URL + "/file/" + label + cloudversion + ".bin",
  646. 'release-url': "http://wiki.moddevices.com/wiki/Control_Chain_Releases#" + label + "," + cloudversion
  647. }
  648. elements.upgradeWindow.upgradeWindow('setupDevice', data)
  649. }
  650. }
  651. this.validatePlugins = function (uris, callback) {
  652. $.ajax({
  653. url: SITEURL + '/pedalboards/validate/',
  654. method: 'POST',
  655. contentType: 'application/json',
  656. data: JSON.stringify({
  657. uris: uris,
  658. }),
  659. success: function (resp) {
  660. if (! resp.result) {
  661. callback(false)
  662. return
  663. }
  664. callback(true)
  665. },
  666. error: function (resp) {
  667. new Bug("Couldn't validate pedalboard, error:<br/>" + resp.statusText)
  668. },
  669. cache: false,
  670. dataType: 'json'
  671. })
  672. }
  673. this.saveConfigValue = function (key, value, callback) {
  674. $.ajax({
  675. url: '/config/set',
  676. type: 'POST',
  677. data: {
  678. key : key,
  679. value: value,
  680. },
  681. success: function () {
  682. if (callback) {
  683. callback(true)
  684. PREFERENCES[key] = value
  685. }
  686. },
  687. error: function () {
  688. if (callback) {
  689. callback(false)
  690. }
  691. },
  692. cache: false,
  693. dataType: 'json'
  694. })
  695. }
  696. this.setupDeviceAuthentication = function () {
  697. self.authenticateDevice(function (ok) {
  698. if (ok) {
  699. console.log("MOD authentication succeeded")
  700. self.resetPedalboardStats();
  701. } else {
  702. console.log("MOD authentication failed")
  703. self.upgradeWindow.upgradeWindow('setErrored')
  704. }
  705. })
  706. }
  707. this.setupMatomo = function() {
  708. // Analytics is for the desktop app only; a MOD device never loads the tracker
  709. if (USING_MOD_DEVICE) {
  710. return
  711. }
  712. var _mtm = window._mtm = window._mtm || [];
  713. _mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
  714. (function() {
  715. var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
  716. g.async=true; g.src='https://cdn.matomo.cloud/modaudio.matomo.cloud/container_DfEOyKDN.js'; s.parentNode.insertBefore(g,s);
  717. })();
  718. }
  719. this.effectBox = self.makeEffectBox(elements.effectBox,
  720. elements.effectBoxTrigger)
  721. this.performanceBox = self.makePerformanceBox(elements.performanceBox,
  722. elements.performanceBoxTrigger)
  723. this.cloudPluginBox = self.makeCloudPluginBox(elements.cloudPluginBox,
  724. elements.cloudPluginBoxTrigger)
  725. this.pedalboardBox = self.makePedalboardBox(elements.pedalboardBox,
  726. elements.pedalboardBoxTrigger)
  727. this.bankBox = self.makeBankBox(elements.bankBox,
  728. elements.bankBoxTrigger)
  729. this.fileManagerBox = self.makeFileManagerBox(elements.fileManagerBox,
  730. elements.fileManagerBoxTrigger)
  731. this.getPluginsData = function (uris, callback) {
  732. $.ajax({
  733. url: '/effect/bulk/',
  734. type: 'POST',
  735. contentType: 'application/json',
  736. data: JSON.stringify(uris),
  737. success: callback,
  738. cache: false,
  739. dataType: 'json'
  740. })
  741. }
  742. this.installMissingPlugins = function (plugins, callback) {
  743. if (self.isApp) {
  744. new Notification('warn', "Cannot load this pedalboard, some plugins are missing", 4000)
  745. callback(false)
  746. return
  747. }
  748. var missingCount = 0
  749. var versions = {}
  750. var uris = []
  751. var error = false
  752. // make list of uris
  753. for (var i in plugins) {
  754. var plugin = plugins[i]
  755. if (uris.indexOf(plugin.uri) < 0) {
  756. versions[plugin.uri] = [plugin.builder || 0, plugin.minorVersion, plugin.microVersion, plugin.release || 0]
  757. uris.push(plugin.uri)
  758. }
  759. }
  760. var finalCallback = function () {
  761. self.previousPedalboardList = null
  762. if (error && !confirm("Failed to install some required plugins, do you want to load the pedalboard anyway?")) {
  763. callback(false)
  764. return
  765. }
  766. callback(true)
  767. }
  768. var installPlugin = function (uri, data) {
  769. missingCount++
  770. self.installationQueue.installUsingURI(uri, function (resp, bundlename) {
  771. if (! resp.ok) {
  772. error = true
  773. }
  774. missingCount--
  775. if (missingCount == 0) {
  776. finalCallback()
  777. }
  778. })
  779. }
  780. var installMissing = function (data) {
  781. for (var i in uris) {
  782. var uri = uris[i]
  783. var localplugin = data[uri]
  784. if (localplugin == null)
  785. {
  786. installPlugin(uri, data)
  787. }
  788. else
  789. {
  790. var version = [localplugin.builder || 0, localplugin.minorVersion, localplugin.microVersion, localplugin.release || 0]
  791. if (compareVersions(version, versions[uri]) < 0) {
  792. installPlugin(uri, data)
  793. }
  794. }
  795. }
  796. if (missingCount == 0) {
  797. finalCallback()
  798. }
  799. }
  800. this.getPluginsData(uris, installMissing)
  801. },
  802. this.loadRemotePedalboard = function (pedalboard_id) {
  803. if (! CLOUD_TERMS_ACCEPTED) {
  804. return
  805. }
  806. self.windowManager.closeWindows(null, true)
  807. if (self.cloudAccessToken == null) {
  808. self.authenticateDevice(function (ok) {
  809. if (ok && self.cloudAccessToken != null) {
  810. self.loadRemotePedalboard(pedalboard_id)
  811. } else {
  812. new Notification('error', "Cannot load remote pedalboards, authentication failure")
  813. }
  814. })
  815. return
  816. }
  817. $.ajax({
  818. url: startsWith(pedalboard_id, 'https://') ? pedalboard_id : (SITEURL + '/pedalboards/' + pedalboard_id),
  819. contentType: 'application/json',
  820. success: function (resp) {
  821. if (resp.data.stable === false && PREFERENCES['show-unstable-plugins'] !== "true") {
  822. new Notification('error', 'This pedalboard contains beta plugins. To load it, you need to enable beta plugins in <a href="settings">Settings</a> -> Developer');
  823. return;
  824. }
  825. self.reset(function () {
  826. self.installMissingPlugins(resp.data.plugins, function (ok) {
  827. if (ok) {
  828. var transfer = new SimpleTransference(resp.file_href, '/pedalboard/load_web/',
  829. { from_args: { headers:
  830. { 'Authorization' : 'MOD ' + self.cloudAccessToken }
  831. }})
  832. transfer.reauthorizeDownload = self.authenticateDevice
  833. transfer.reportFinished = function () {
  834. self.pedalboardEmpty = false
  835. self.setPedalboardAsModified(true)
  836. }
  837. transfer.reportError = function (error) {
  838. new Bug("Couldn't load pedalboard, reason:<br/>" + error)
  839. }
  840. transfer.start()
  841. } else {
  842. self.pedalboard.data('wait').stop()
  843. }
  844. })
  845. }, true)
  846. },
  847. error: function (resp) {
  848. new Bug("Couldn't get pedalboard info, error:<br/>" + resp.statusText)
  849. },
  850. cache: false,
  851. dataType: 'json'
  852. })
  853. },
  854. this.waitForScreenshot = function (generate, bundlepath, callback) {
  855. pending_pedalboard_screenshots.push(bundlepath)
  856. if (generate) {
  857. $.ajax({
  858. url: "/pedalboard/image/generate?bundlepath="+escape(bundlepath),
  859. success: function (resp) {
  860. callback(resp.ok)
  861. },
  862. error: function () {
  863. callback(false)
  864. },
  865. cache: false,
  866. dataType: 'json'
  867. })
  868. } else {
  869. $.ajax({
  870. url: "/pedalboard/image/wait?bundlepath="+escape(bundlepath),
  871. success: function (resp) {
  872. callback(resp.ok)
  873. },
  874. error: function () {
  875. callback(false)
  876. },
  877. cache: false,
  878. dataType: 'json'
  879. })
  880. }
  881. },
  882. this.saveBox = elements.saveBox.saveBox({
  883. save: function (windotTitle, name, asNew, callback) {
  884. $.ajax({
  885. url: '/pedalboard/save',
  886. type: 'POST',
  887. data: {
  888. title: name,
  889. asNew: asNew ? 1 : 0
  890. },
  891. success: function (result) {
  892. if (result.ok) {
  893. // dummy call to keep 1 ajax request active while screenshot is generated
  894. self.waitForScreenshot(false, result.bundlepath, function(){})
  895. // all set
  896. callback(true, result.bundlepath, result.title)
  897. _paq.push(['trackEvent', 'pedalboard', 'pedalboard-save'])
  898. } else {
  899. callback(false, "Failed to save")
  900. }
  901. },
  902. error: function (resp) {
  903. self.saveBox.hide()
  904. callback(false, "Couldn't save pedalboard")
  905. },
  906. cache: false,
  907. dataType: 'json'
  908. });
  909. }
  910. })
  911. this.presetSaveBox = elements.presetSaveBox.saveBox({
  912. save: function (windotTitle, name, asNew, callback) {
  913. callback(true, "", name)
  914. }
  915. })
  916. this.inputBox = elements.inputBox.inputBox({})
  917. elements.addMidiButton.click(function () {
  918. self.showMidiDeviceList()
  919. })
  920. elements.saveButton.click(function () {
  921. self.saveCurrentPedalboard(false)
  922. })
  923. elements.saveAsButton.click(function () {
  924. self.saveCurrentPedalboard(true)
  925. })
  926. elements.cvAddressingButton.click(function () {
  927. // Show/hide CV checkboxes
  928. if ($(this).hasClass('selected')) {
  929. $('body').find('.output-cv-checkbox').hide()
  930. } else {
  931. $('body').find('.output-cv-checkbox').show()
  932. }
  933. // Toggle cvAddressing and button state
  934. self.cvAddressing = !self.cvAddressing
  935. self.pedalboard.pedalboard('setCvAddressing', self.cvAddressing)
  936. $(this).toggleClass('selected')
  937. })
  938. elements.resetButton.click(function () {
  939. self.reset(function () {
  940. $.ajax({
  941. url: '/pedalboard/load_bundle/',
  942. type: 'POST',
  943. data: {
  944. bundlepath: DEFAULT_PEDALBOARD,
  945. isDefault: '1',
  946. },
  947. cache: false,
  948. dataType: 'json'
  949. })
  950. })
  951. })
  952. elements.snapshotSaveButton.click(function () {
  953. if (self.pedalboardPresetId < 0) {
  954. return new Notification('warn', 'Nothing to save', 1500)
  955. }
  956. $.ajax({
  957. url: '/snapshot/save',
  958. method: 'POST',
  959. success: function () {
  960. new Notification('info', 'Pedalboard snapshot saved', 2000)
  961. },
  962. error: function () {
  963. new Bug("Failed to save pedalboard snapshot")
  964. },
  965. cache: false,
  966. dataType: 'json',
  967. })
  968. })
  969. elements.snapshotSaveAsButton.click(function () {
  970. var addressed = !!self.hardwareManager.addressingsByPortSymbol['/pedalboard/:presets']
  971. if (addressed) {
  972. return new Notification("warn", "Cannot change snapshot while addressed to hardware", 3000)
  973. }
  974. desktop.openPresetSaveWindow("Saving Snapshot", "", function (newName) {
  975. $.ajax({
  976. url: '/snapshot/saveas',
  977. data: {
  978. title: newName,
  979. },
  980. success: function (resp) {
  981. if (! resp.ok) {
  982. return
  983. }
  984. self.pedalboardPresetId = resp.id
  985. self.pedalboardPresetName = resp.title
  986. const newTitle = (self.title || 'Untitled') + " - " + resp.title
  987. self.titleBox.text(newTitle)
  988. self.performanceTitleBox.text(newTitle)
  989. new Notification('info', 'Pedalboard snapshot saved', 2000)
  990. },
  991. error: function () {
  992. new Bug("Failed to save pedalboard snapshot")
  993. },
  994. cache: false,
  995. dataType: 'json',
  996. })
  997. })
  998. })
  999. elements.snapshotManageButton.click(function () {
  1000. var addressed = !!self.hardwareManager.addressingsByPortSymbol['/pedalboard/:presets']
  1001. var feedback = true
  1002. if (addressed) {
  1003. console.log(self.hardwareManager.addressingsData['/pedalboard/:presets'])
  1004. feedback = self.hardwareManager.addressingsData['/pedalboard/:presets'].feedback
  1005. }
  1006. self.pedalPresets.start(self.pedalboardPresetId, addressed, feedback)
  1007. })
  1008. elements.bypassLeftButton.click(function () {
  1009. self.triggerTrueBypass("Left", !$(this).hasClass("bypassed"))
  1010. })
  1011. elements.bypassRightButton.click(function () {
  1012. self.triggerTrueBypass("Right", !$(this).hasClass("bypassed"))
  1013. })
  1014. elements.bufferSizeButton.click(function () {
  1015. var newsize
  1016. if ($(this).text() == "128 frames") {
  1017. newsize = '256'
  1018. } else {
  1019. newsize = '128'
  1020. }
  1021. $.ajax({
  1022. url: '/set_buffersize/' + newsize,
  1023. method: 'POST',
  1024. cache: false,
  1025. success: function (resp) {
  1026. if (! resp.ok) {
  1027. new Bug("Couldn't set new buffer size")
  1028. }
  1029. },
  1030. error: function () {
  1031. new Bug("Communication failure")
  1032. },
  1033. })
  1034. })
  1035. elements.xrunsButton.click(function () {
  1036. if (cached_xruns == 0) {
  1037. return
  1038. }
  1039. $.ajax({
  1040. url: '/reset_xruns/',
  1041. method: 'POST',
  1042. cache: false,
  1043. success: function (ok) {
  1044. if (ok) {
  1045. cached_xruns = 0
  1046. $("#mod-xruns").text("0 Xruns")
  1047. }
  1048. }
  1049. })
  1050. })
  1051. elements.cpuButton.click(function () {
  1052. self.cpuLoadPanel.toggle()
  1053. })
  1054. elements.cpuLoadWindow.find('.js-close').click(function () {
  1055. self.cpuLoadPanel.close()
  1056. })
  1057. elements.cpuLoadWindow.find('.js-reset-peaks').click(function () {
  1058. self.cpuLoadPanel.reset()
  1059. })
  1060. elements.cpuLoadWindow.click(function (e) {
  1061. if (e.target === this) {
  1062. self.cpuLoadPanel.close()
  1063. }
  1064. })
  1065. elements.cpuStatsButton.click(function () {
  1066. $.ajax({
  1067. url: '/switch_cpu_freq/',
  1068. method: 'POST',
  1069. cache: false,
  1070. success: function (ok) {
  1071. if (! ok) {
  1072. new Bug("Couldn't set new cpu frequency")
  1073. }
  1074. },
  1075. error: function () {
  1076. new Bug("Communication failure")
  1077. },
  1078. })
  1079. })
  1080. elements.shareButton.click(function () {
  1081. var share = function () {
  1082. if (self.pedalboardEmpty) {
  1083. return new Notification('warn', 'Nothing to share', 1500)
  1084. }
  1085. var uris = self.pedalboard.pedalboard('getLoadedPluginURIs')
  1086. if (uris.length == 0) {
  1087. return new Notification('warn', 'No plugins loaded, cannot share', 1500)
  1088. }
  1089. self.validatePlugins(uris, function (stable) {
  1090. elements.shareWindow.shareBox('open', self.pedalboardBundle, self.title, stable)
  1091. })
  1092. }
  1093. if (self.pedalboardModified || ! (self.pedalboardEmpty || self.pedalboardBundle)) {
  1094. if (confirm('There are unsaved modifications, pedalboard must first be saved. Save it?')) {
  1095. self.saveCurrentPedalboard(false, share)
  1096. }
  1097. } else {
  1098. share()
  1099. }
  1100. })
  1101. elements.shareWindow.shareBox({
  1102. recordStart: ajaxFactory('/recording/start', "Can't record. Probably a connection problem."),
  1103. recordStop: ajaxFactory('/recording/stop', "Can't stop record. Probably a connection problem. Please try stopping again"),
  1104. playStart: function (startCallback, stopCallback) {
  1105. $.ajax({
  1106. url: '/recording/play/start',
  1107. success: function (resp) {
  1108. $.ajax({
  1109. url: '/recording/play/wait',
  1110. success: stopCallback,
  1111. error: function () {
  1112. new Error("Couln't check when sample playing has ended")
  1113. },
  1114. cache: false,
  1115. dataType: 'json'
  1116. })
  1117. startCallback(resp)
  1118. },
  1119. error: function () {
  1120. new Error("Can't play. Probably a connection problem.")
  1121. },
  1122. cache: false,
  1123. dataType: 'json'
  1124. })
  1125. },
  1126. playStop: ajaxFactory('/recording/play/stop', "Can't stop playing. Probably a connection problem. Please try stopping again"),
  1127. recordDownload: ajaxFactory('/recording/download', "Can't download recording. Probably a connection problem."),
  1128. recordReset: ajaxFactory('/recording/reset', "Can't reset your recording. Probably a connection problem."),
  1129. share: function (data, callback) {
  1130. if (! data.reauthorized) {
  1131. // save user data
  1132. $.ajax({
  1133. url: '/save_user_id/',
  1134. method: 'POST',
  1135. data: data,
  1136. success: function () {},
  1137. error: function () {},
  1138. cache: false,
  1139. global: false,
  1140. dataType: 'json',
  1141. })
  1142. }
  1143. if (! CLOUD_TERMS_ACCEPTED) {
  1144. return
  1145. }
  1146. if (self.cloudAccessToken == null) {
  1147. self.authenticateDevice(function (ok) {
  1148. if (ok && self.cloudAccessToken != null) {
  1149. elements.shareWindow.shareBox('share', data, callback)
  1150. } else {
  1151. callback({
  1152. ok: false,
  1153. error: "authentication failure"
  1154. })
  1155. }
  1156. })
  1157. return
  1158. }
  1159. // pack & upload to cloud
  1160. $.ajax({
  1161. url: SITEURL + '/pedalboards/',
  1162. method: 'POST',
  1163. contentType: 'application/json',
  1164. headers: { 'Authorization' : 'MOD ' + self.cloudAccessToken },
  1165. data: JSON.stringify({
  1166. author : data.name,
  1167. email : data.email,
  1168. description: data.description,
  1169. title : data.title,
  1170. hidden : data.hidden,
  1171. }),
  1172. success: function (resp) {
  1173. var transfer = new SimpleTransference('/pedalboard/pack_bundle/?bundlepath=' + escape(self.pedalboardBundle),
  1174. resp.upload_href,
  1175. { to_args: { headers:
  1176. { 'Authorization' : 'MOD ' + self.cloudAccessToken }
  1177. }})
  1178. transfer.reauthorizeUpload = self.authenticateDevice;
  1179. transfer.reportFinished = function (resp2) {
  1180. callback({
  1181. ok: true,
  1182. id: resp.id,
  1183. })
  1184. }
  1185. transfer.reportError = function (error) {
  1186. callback({
  1187. ok: false,
  1188. error: "Failed to upload pedalboard to cloud (missing screenshot?)",
  1189. })
  1190. }
  1191. transfer.start()
  1192. },
  1193. error: function (resp) {
  1194. if (resp.status == 401 && ! data.reauthorized) {
  1195. console.log("Pedalboard share unauthorized, retrying authentication...")
  1196. data.reauthorized = true
  1197. self.authenticateDevice(function (ok, options) {
  1198. if (ok) {
  1199. console.log("Authentication succeeded")
  1200. self.options = $.extend(self.options, options)
  1201. elements.shareWindow.shareBox('share', data, callback)
  1202. } else {
  1203. console.log("Authentication failed")
  1204. callback({
  1205. ok: false,
  1206. error: resp.statusText
  1207. })
  1208. }
  1209. })
  1210. return;
  1211. }
  1212. callback({
  1213. ok: false,
  1214. error: resp.statusText
  1215. })
  1216. },
  1217. cache: false,
  1218. dataType: 'json'
  1219. })
  1220. },
  1221. waitForScreenshot: self.waitForScreenshot,
  1222. })
  1223. elements.statusIcon.statusTooltip()
  1224. this.networkStatus = new NetworkStatus({
  1225. icon: elements.statusIcon,
  1226. notify: function (msg) {
  1227. elements.statusIcon.statusTooltip('message', msg, true)
  1228. }
  1229. })
  1230. elements.settingsIcon.click(function() {
  1231. document.location.href = '/settings';
  1232. })
  1233. elements.settingsIcon.statusTooltip()
  1234. elements.pedalboardTrigger.statusTooltip()
  1235. elements.performanceBoxTrigger.statusTooltip()
  1236. elements.pedalboardBoxTrigger.statusTooltip()
  1237. elements.bankBoxTrigger.statusTooltip()
  1238. elements.cloudPluginBoxTrigger.statusTooltip()
  1239. elements.fileManagerBoxTrigger.statusTooltip()
  1240. this.upgradeWindow = elements.upgradeWindow.upgradeWindow({
  1241. icon: elements.upgradeIcon,
  1242. windowManager: self.windowManager,
  1243. startUpgrade: function (callback) {
  1244. $.ajax({
  1245. type: 'POST',
  1246. url: '/update/begin',
  1247. success: function (ok) {
  1248. callback(ok)
  1249. },
  1250. error: function () {
  1251. callback(false)
  1252. },
  1253. cache: false,
  1254. dataType: 'json',
  1255. })
  1256. },
  1257. startDeviceUpgrade: function () {
  1258. self.ccDeviceManager.showUpdateWindow()
  1259. },
  1260. })
  1261. this.onPedalboardLoadComplete = function (callback) {
  1262. if (callback) {
  1263. callback()
  1264. }
  1265. }
  1266. // this callback is called when the pedalboard is loaded for the first time
  1267. this.onPedalboardFirstLoadComplete = function (callback) {
  1268. // The plugin bar does not depend on the board, so the first fit no longer waits for
  1269. // its list (and 300-odd thumbnails on a device) to load.
  1270. self.effectBox.effectBox('search', function () {
  1271. setTimeout(function () {
  1272. // if is a touch device, open performance view by default
  1273. if (self.isTouchDevice) {
  1274. elements.performanceBoxTrigger.click()
  1275. }
  1276. }, 500)
  1277. })
  1278. self.onPedalboardLoadComplete(callback)
  1279. }
  1280. var prevent = function (ev) {
  1281. ev.preventDefault()
  1282. }
  1283. $('body')[0].addEventListener('gesturestart', prevent)
  1284. $('body')[0].addEventListener('gesturechange', prevent)
  1285. $('body')[0].addEventListener('touchmove', prevent)
  1286. $('body')[0].addEventListener('dblclick', prevent)
  1287. }
  1288. Desktop.prototype.makePedalboard = function (el, effectBox) {
  1289. var self = this
  1290. el.pedalboard({
  1291. windowManager: self.windowManager,
  1292. hardwareManager: self.hardwareManager,
  1293. bottomMargin: effectBox.height(),
  1294. cvAddressing: self.cvAddressing,
  1295. pluginLoad: function (uri, instance, x, y, callback, errorCallback) {
  1296. var firstTry = true
  1297. var add = function () {
  1298. $.ajax({
  1299. url: '/effect/add/' + instance + '?x=' + x + '&y=' + y + '&uri=' + escape(uri),
  1300. success: function (pluginData) {
  1301. if (pluginData) {
  1302. callback(pluginData)
  1303. } else {
  1304. new Notification('error', 'Error adding effect')
  1305. if (errorCallback)
  1306. errorCallback()
  1307. }
  1308. },
  1309. error: function (resp) {
  1310. new Notification('error', 'Error adding effect. Probably a connection problem.')
  1311. if (errorCallback)
  1312. errorCallback()
  1313. },
  1314. cache: false,
  1315. dataType: 'json'
  1316. })
  1317. }
  1318. add()
  1319. },
  1320. pluginRemove: function (instance, callback) {
  1321. $.ajax({
  1322. url: '/effect/remove/' + instance,
  1323. success: function (resp) {
  1324. if (resp)
  1325. callback()
  1326. else
  1327. new Notification("error", "Couldn't remove effect")
  1328. },
  1329. cache: false,
  1330. dataType: 'json'
  1331. })
  1332. },
  1333. pluginPresetLoad: function (instance, uri, callback) {
  1334. $.ajax({
  1335. url: '/effect/preset/load/' + instance,
  1336. data: {
  1337. uri: uri
  1338. },
  1339. success: function (resp) {
  1340. callback(resp)
  1341. },
  1342. error: function () {
  1343. },
  1344. cache: false,
  1345. dataType: 'json'
  1346. })
  1347. },
  1348. pluginPresetSaveNew: function (instance, name, callback) {
  1349. $.ajax({
  1350. url: '/effect/preset/save_new/' + instance,
  1351. data: {
  1352. name: name
  1353. },
  1354. success: function (resp) {
  1355. callback(resp)
  1356. },
  1357. error: function () {
  1358. },
  1359. cache: false,
  1360. dataType: 'json'
  1361. })
  1362. },
  1363. pluginPresetSaveReplace: function (instance, uri, bundlepath, name, callback) {
  1364. $.ajax({
  1365. url: '/effect/preset/save_replace/' + instance,
  1366. data: {
  1367. uri : uri,
  1368. bundle: bundlepath,
  1369. name : name
  1370. },
  1371. success: function (resp) {
  1372. callback(resp)
  1373. },
  1374. error: function () {
  1375. },
  1376. cache: false,
  1377. dataType: 'json'
  1378. })
  1379. },
  1380. // .modpreset download of the current plugin settings
  1381. pluginPresetExport: function (instance, name, callback) {
  1382. var xhr = new XMLHttpRequest()
  1383. xhr.open('GET', '/effect/preset/export' + instance + '?name=' + encodeURIComponent(name) + '&_=' + Date.now())
  1384. xhr.responseType = 'blob'
  1385. xhr.onload = function () {
  1386. if (xhr.status != 200) {
  1387. var reader = new FileReader()
  1388. reader.onload = function () {
  1389. callback({ ok: false, error: reader.result || "Export failed" })
  1390. }
  1391. reader.readAsText(xhr.response)
  1392. return
  1393. }
  1394. var filename = xhr.getResponseHeader('X-Modpreset-Filename') || 'preset.modpreset'
  1395. var url = URL.createObjectURL(xhr.response)
  1396. var a = $('<a style="display:none">').attr('href', url).attr('download', filename).appendTo('body')
  1397. a[0].click()
  1398. setTimeout(function () {
  1399. a.remove()
  1400. URL.revokeObjectURL(url)
  1401. }, 1000)
  1402. callback({
  1403. ok: true,
  1404. filename: filename,
  1405. leftOut: parseInt(xhr.getResponseHeader('X-Modpreset-Left-Out') || '0'),
  1406. })
  1407. }
  1408. xhr.onerror = function () {
  1409. callback({ ok: false, error: "Export failed" })
  1410. }
  1411. xhr.send()
  1412. },
  1413. // .modpreset file (a File from an <input type=file>) installed as a user preset
  1414. pluginPresetImport: function (instance, file, callback) {
  1415. $.ajax({
  1416. url: '/effect/preset/import' + instance,
  1417. method: 'POST',
  1418. data: file,
  1419. processData: false,
  1420. contentType: 'application/octet-stream',
  1421. success: function (resp) {
  1422. callback(resp)
  1423. },
  1424. error: function () {
  1425. callback({ ok: false, error: "Import failed" })
  1426. },
  1427. cache: false,
  1428. dataType: 'json'
  1429. })
  1430. },
  1431. pluginPresetDelete: function (instance, uri, bundlepath, callback) {
  1432. $.ajax({
  1433. url: '/effect/preset/delete/' + instance,
  1434. data: {
  1435. uri : uri,
  1436. bundle: bundlepath
  1437. },
  1438. success: function (resp) {
  1439. callback(resp)
  1440. },
  1441. error: function () {
  1442. },
  1443. cache: false,
  1444. dataType: 'json'
  1445. })
  1446. },
  1447. portConnect: function (fromPort, toPort, callback) {
  1448. var urlParam = fromPort + ',' + toPort
  1449. $.ajax({
  1450. url: '/effect/connect/' + urlParam,
  1451. success: function (resp) {
  1452. callback(resp)
  1453. if (!resp) {
  1454. console.log('erro')
  1455. }
  1456. },
  1457. cache: false,
  1458. dataType: 'json'
  1459. })
  1460. },
  1461. portDisconnect: function (fromPort, toPort, callback) {
  1462. var urlParam = fromPort + ',' + toPort
  1463. $.ajax({
  1464. url: '/effect/disconnect/' + urlParam,
  1465. success: function () {
  1466. callback(true)
  1467. },
  1468. cache: false,
  1469. dataType: 'json'
  1470. })
  1471. },
  1472. reset: function (callback) {
  1473. $.ajax({
  1474. url: '/reset',
  1475. success: function (resp) {
  1476. if (!resp) {
  1477. return new Notification('error', "Couldn't reset pedalboard")
  1478. }
  1479. self.title = ''
  1480. self.pedalboardBundle = null
  1481. self.pedalboardEmpty = true
  1482. self.pedalboardPresetId = 0
  1483. self.pedalboardPresetName = ''
  1484. self.pedalboardDemoPluginsNotified = false
  1485. self.titleBox.text('Untitled')
  1486. self.performanceTitleBox.text('Untitled')
  1487. self.titleBox.addClass("blend")
  1488. self.transportControls.resetControlsEnabled()
  1489. self.setPedalboardAsModified(false)
  1490. callback(true)
  1491. },
  1492. error: function () {
  1493. new Bug("Couldn't reset pedalboard")
  1494. },
  1495. cache: false
  1496. })
  1497. },
  1498. getPluginsData: self.getPluginsData,
  1499. showPluginInfo: function (pluginData) {
  1500. pluginData.installedVersion = [pluginData.builder,
  1501. pluginData.minorVersion,
  1502. pluginData.microVersion,
  1503. pluginData.release]
  1504. self.effectBox.effectBox('showPluginInfo', pluginData)
  1505. },
  1506. showExternalUI: function (instance) {
  1507. ws.send(sprintf("show_external_ui %s", instance))
  1508. },
  1509. pluginParameterChange: function (port, value) {
  1510. self.setPedalboardAsModified(true)
  1511. ws.send(sprintf("param_set %s %f", port, value))
  1512. },
  1513. pluginPatchGet: function (instance, uri) {
  1514. ws.send(sprintf("patch_get %s %s", instance, uri))
  1515. },
  1516. pluginPatchSet: function (instance, uri, valuetype, value) {
  1517. self.setPedalboardAsModified(true)
  1518. ws.send(sprintf("patch_set %s %s %s %s", instance, uri, valuetype, value))
  1519. },
  1520. pluginMove: function (instance, x, y) {
  1521. self.setPedalboardAsModified(true)
  1522. ws.send(sprintf("plugin_pos %s %f %f", instance, x, y))
  1523. },
  1524. /*
  1525. * Set the label of a plugin instance
  1526. * label: string or null, undefined, empty string to reset to default
  1527. */
  1528. pluginLabelSet: function (instance, label) {
  1529. self.setPedalboardAsModified(true)
  1530. ws.send(sprintf("plugin_label %s %s", instance, label?.replace(/ /g, '_')))
  1531. },
  1532. /*
  1533. * Set if the plugin instance should be displayed on the performance view
  1534. * visible: true to display, else false
  1535. */
  1536. performancePluginVisibilitySet: function (instance, visible) {
  1537. self.setPedalboardAsModified(true)
  1538. ws.send(sprintf("performance_plugin_visibility %s %s", instance, (visible ? "1" : "0")))
  1539. },
  1540. /*
  1541. * Set if the order of the plugin instance in the performance view
  1542. * index: order
  1543. */
  1544. performancePluginIndexSet: function (instance, index) {
  1545. self.setPedalboardAsModified(true)
  1546. ws.send(sprintf("performance_plugin_index %s %d", instance, index))
  1547. },
  1548. windowSize: function (width, height) {
  1549. // FIXME
  1550. if (ws && width > 0 && height > 0) {
  1551. ws.send(sprintf("pb_size %f %f", width, height))
  1552. }
  1553. },
  1554. pedalboardFinishedLoading: function (callback) {
  1555. if (self.loadingPeldaboardForFirstTime) {
  1556. self.loadingPeldaboardForFirstTime = false
  1557. self.onPedalboardFirstLoadComplete(callback)
  1558. } else {
  1559. self.onPedalboardLoadComplete(callback)
  1560. }
  1561. },
  1562. addCVAddressingPluginPort: function (uri, name, callback) {
  1563. $.ajax({
  1564. url: '/pedalboard/cv_addressing_plugin_port/add',
  1565. type: 'POST',
  1566. data: {
  1567. uri: uri,
  1568. name: name,
  1569. },
  1570. success: function (resp) {
  1571. if (!resp) {
  1572. return new Notification('error', "Couldn't add CV port")
  1573. }
  1574. callback(resp)
  1575. },
  1576. error: function () {
  1577. new Bug("Couldn't add CV port")
  1578. },
  1579. cache: false,
  1580. dataType: 'json'
  1581. })
  1582. },
  1583. removeCVAddressingPluginPort: function (uri, callback) {
  1584. $.ajax({
  1585. url: '/pedalboard/cv_addressing_plugin_port/remove',
  1586. type: 'POST',
  1587. data: {
  1588. uri: uri,
  1589. },
  1590. success: function (resp) {
  1591. if (!resp) {
  1592. return new Notification('error', "Couldn't remove CV port")
  1593. }
  1594. callback(resp)
  1595. },
  1596. error: function () {
  1597. new Bug("Couldn't remove CV port")
  1598. },
  1599. cache: false,
  1600. dataType: 'json'
  1601. })
  1602. },
  1603. notifyDemoPluginLoaded: function () {
  1604. if (self.pedalboardDemoPluginsNotified) {
  1605. return
  1606. }
  1607. self.pedalboardDemoPluginsNotified = true
  1608. new Notification('warn', 'This pedalboard contains a trial plugin.<br>Using trial plugins will intentionally mute the audio at regular intervals.')
  1609. },
  1610. });
  1611. // Bind events
  1612. el.bind('modified', function () {
  1613. self.pedalboardEmpty = false
  1614. self.setPedalboardAsModified(true)
  1615. })
  1616. /*
  1617. el.bind('dragStart', function () {
  1618. self.windowManager.closeWindows(null, true)
  1619. })
  1620. */
  1621. el.bind('pluginDragStart', function () {
  1622. self.effectBox.addClass('fade')
  1623. })
  1624. el.bind('pluginDragStop', function () {
  1625. self.effectBox.removeClass('fade')
  1626. })
  1627. return el
  1628. }
  1629. Desktop.prototype.makePedalboardBox = function (el, trigger) {
  1630. var self = this
  1631. return el.pedalboardBox({
  1632. trigger: trigger,
  1633. windowManager: this.windowManager,
  1634. list: self.pedalboardListFunction,
  1635. search: self.pedalboardSearchFunction,
  1636. saveConfigValue: self.saveConfigValue,
  1637. exportFile: function (pedalboard) {
  1638. self.exportPedalboardFile(pedalboard)
  1639. },
  1640. importFile: function (file, callback) {
  1641. self.importPedalboardFile(file, callback)
  1642. },
  1643. remove: function (pedalboard, callback) {
  1644. if (!confirm(sprintf('The pedalboard "%s" will be permanently removed! Confirm?', pedalboard.title)))
  1645. return
  1646. $.ajax({
  1647. url: '/pedalboard/remove/',
  1648. data: {
  1649. bundlepath: pedalboard.bundle
  1650. },
  1651. success: function () {
  1652. new Notification("info", sprintf('Pedalboard "%s" removed', pedalboard.title), 1000)
  1653. self.previousPedalboardList = null
  1654. callback()
  1655. },
  1656. error: function () {
  1657. new Bug("Couldn't remove pedalboard")
  1658. },
  1659. cache: false
  1660. })
  1661. },
  1662. load: function (bundlepath, broken, callback) {
  1663. if (!broken) {
  1664. self.loadPedalboard(bundlepath, callback)
  1665. return
  1666. }
  1667. $.ajax({
  1668. url: '/pedalboard/info/',
  1669. data: {
  1670. bundlepath: bundlepath
  1671. },
  1672. success: function (pbinfo) {
  1673. self.reset(function () {
  1674. self.installMissingPlugins(pbinfo.plugins, function (ok) {
  1675. if (ok) {
  1676. self.loadPedalboard(bundlepath, callback)
  1677. } else {
  1678. self.pedalboard.data('wait').stop()
  1679. }
  1680. })
  1681. })
  1682. },
  1683. error: function () {
  1684. new Bug("Couldn't load pedalboard")
  1685. },
  1686. cache: false
  1687. })
  1688. },
  1689. })
  1690. }
  1691. Desktop.prototype.makePerformanceBox = function (el, trigger) {
  1692. return el.performanceBox({
  1693. trigger: trigger,
  1694. windowManager: this.windowManager,
  1695. pedalboard: this.pedalboard,
  1696. pedalPresets: this.pedalPresets,
  1697. saveConfigValue: self.saveConfigValue,
  1698. })
  1699. }
  1700. Desktop.prototype.makeEffectBox = function (el, trigger) {
  1701. var self = this
  1702. return el.effectBox({
  1703. trigger: trigger,
  1704. windowManager: this.windowManager,
  1705. pedalboard: this.pedalboard,
  1706. saveConfigValue: this.saveConfigValue,
  1707. })
  1708. }
  1709. Desktop.prototype.makeCloudPluginBox = function (el, trigger) {
  1710. var self = this
  1711. return el.cloudPluginBox({
  1712. trigger: trigger,
  1713. windowManager: this.windowManager,
  1714. list: self.cloudPluginListFunction,
  1715. removePluginBundles: function (bundles, callback) {
  1716. if (!confirm('You are about to remove this plugin and any other in the same bundle. This may break pedalboards that depend on them.'))
  1717. return
  1718. self.previousPedalboardList = null
  1719. $.ajax({
  1720. url: '/package/uninstall',
  1721. data: JSON.stringify(bundles),
  1722. method: 'POST',
  1723. success: function(resp) {
  1724. if (resp.ok) {
  1725. callback(resp)
  1726. } else {
  1727. new Notification('error', "Could not uninstall bundle: " + resp.error)
  1728. }
  1729. },
  1730. error: function () {
  1731. new Notification('error', "Failed to uninstall plugin")
  1732. },
  1733. cache: false,
  1734. dataType: 'json'
  1735. })
  1736. },
  1737. upgradePluginURI: function (uri, callback) {
  1738. self.previousPedalboardList = null
  1739. self.installationQueue.installUsingURI(uri, callback)
  1740. },
  1741. installPluginURI: function (uri, callback) {
  1742. self.previousPedalboardList = null
  1743. self.installationQueue.installUsingURI(uri, callback)
  1744. }
  1745. })
  1746. }
  1747. Desktop.prototype.makeBankBox = function (el, trigger) {
  1748. var self = this
  1749. el.bankBox({
  1750. trigger: trigger,
  1751. windowManager: this.windowManager,
  1752. list: self.pedalboardListFunction,
  1753. search: self.pedalboardSearchFunction,
  1754. load: function (callback) {
  1755. $.ajax({
  1756. url: '/banks',
  1757. success: callback,
  1758. error: function () {
  1759. new Bug("Couldn't load banks")
  1760. },
  1761. cache: false,
  1762. dataType: 'json',
  1763. })
  1764. },
  1765. save: function (data, callback) {
  1766. $.ajax({
  1767. type: 'POST',
  1768. url: '/banks/save',
  1769. data: JSON.stringify(data),
  1770. success: callback,
  1771. error: function () {
  1772. new Bug("Couldn't save banks")
  1773. },
  1774. cache: false,
  1775. })
  1776. },
  1777. copyFactoryPedalboard: function (bundlepath, title, callback) {
  1778. $.ajax({
  1779. url: '/pedalboard/factorycopy/',
  1780. data: {
  1781. bundlepath: bundlepath,
  1782. title: title,
  1783. },
  1784. success: function (resp) {
  1785. if (resp) {
  1786. self.previousPedalboardList = null
  1787. new Notification('warning', 'Factory pedalboard was duplicated into the User Pedalboards Library')
  1788. callback(resp)
  1789. } else {
  1790. new Bug("Could not copy factory pedalboard")
  1791. }
  1792. },
  1793. error: function () {
  1794. new Bug("Failed to copy factory pedalboard")
  1795. },
  1796. cache: false
  1797. })
  1798. },
  1799. })
  1800. }
  1801. Desktop.prototype.makeFileManagerBox = function (el, trigger) {
  1802. var self = this
  1803. el.fileManagerBox({
  1804. trigger: trigger,
  1805. windowManager: this.windowManager,
  1806. })
  1807. }
  1808. Desktop.prototype.reset = function (callback, skipConfirmDialog) {
  1809. if (this.pedalboardModified && !skipConfirmDialog && !confirm("There are unsaved modifications that will be lost. Are you sure?")) {
  1810. return
  1811. }
  1812. this.pedalboard.data('wait').start('Loading pedalboard...')
  1813. this.pedalboard.pedalboard('reset', callback)
  1814. }
  1815. Desktop.prototype.updateAllPlugins = function () {
  1816. this.effectBox.effectBox('search')
  1817. }
  1818. Desktop.prototype.updatePluginList = function (added, removed) {
  1819. // TODO
  1820. console.log("ADDED:", added)
  1821. console.log("REMOVED:", removed)
  1822. for (var i in added) {
  1823. var uri = added[i]
  1824. }
  1825. for (var i in removed) {
  1826. var uri = removed[i]
  1827. }
  1828. this.effectBox.effectBox('search')
  1829. }
  1830. Desktop.prototype.showMidiDeviceList = function () {
  1831. this.midiDevices.start()
  1832. }
  1833. Desktop.prototype.triggerTrueBypass = function (channelName, bypassed) {
  1834. var self = this;
  1835. $.ajax({
  1836. url: '/truebypass/' + channelName + '/' + (bypassed ? "true" : "false"),
  1837. cache: false,
  1838. dataType: 'json',
  1839. success: function (ok) {
  1840. if (ok) {
  1841. self.setTrueBypassButton(channelName, bypassed);
  1842. }
  1843. }
  1844. })
  1845. }
  1846. Desktop.prototype.setTrueBypassButton = function (channelName, state) {
  1847. if (typeof state === "string") state = eval(state);
  1848. var b = $("#mod-bypass" + channelName);
  1849. b[(state ? "add" : "remove") + "Class"]("bypassed");
  1850. }
  1851. // .modpedalboard download of a saved pedalboard (Developer Mode, always on MOD Desktop)
  1852. Desktop.prototype.exportPedalboardFile = function (pedalboard) {
  1853. if (pedalboard.bundle == this.pedalboardBundle && this.pedalboardModified) {
  1854. new Notification('warn', 'This pedalboard has unsaved changes: the export holds the last saved version', 5000)
  1855. }
  1856. var xhr = new XMLHttpRequest()
  1857. xhr.open('GET', '/pedalboard/file/export/?bundlepath=' + encodeURIComponent(pedalboard.bundle) + '&_=' + Date.now())
  1858. xhr.responseType = 'blob'
  1859. xhr.onload = function () {
  1860. if (xhr.status != 200) {
  1861. var reader = new FileReader()
  1862. reader.onload = function () {
  1863. new Notification('error', 'Export failed: ' + $('<div>').text(reader.result || "unknown error").html(), 6000)
  1864. }
  1865. reader.readAsText(xhr.response)
  1866. return
  1867. }
  1868. var filename = xhr.getResponseHeader('X-Modpedalboard-Filename') || ('pedalboard' + PEDALBOARD_FILE_EXTENSION)
  1869. var files = parseInt(xhr.getResponseHeader('X-Modpedalboard-Files') || '0')
  1870. var url = URL.createObjectURL(xhr.response)
  1871. var a = $('<a style="display:none">').attr('href', url).attr('download', filename).appendTo('body')
  1872. a[0].click()
  1873. setTimeout(function () {
  1874. a.remove()
  1875. URL.revokeObjectURL(url)
  1876. }, 1000)
  1877. var msg = 'Pedalboard exported as ' + $('<div>').text(filename).html()
  1878. if (files > 0) {
  1879. msg += '<br/>The ' + files + ' user file' + (files == 1 ? '' : 's') + ' it uses (NAM models, IRs, ...) are not included.'
  1880. }
  1881. new Notification('info', msg, 6000)
  1882. }
  1883. xhr.onerror = function () {
  1884. new Notification('error', 'Export failed: communication failure', 6000)
  1885. }
  1886. xhr.send()
  1887. }
  1888. // .modpedalboard file loaded as an unsaved pedalboard: check, install missing plugins (devices), load
  1889. Desktop.prototype.importPedalboardFile = function (file, closeWindow) {
  1890. var self = this
  1891. $.ajax({
  1892. url: '/pedalboard/file/import/',
  1893. method: 'POST',
  1894. data: file,
  1895. processData: false,
  1896. contentType: 'application/octet-stream',
  1897. cache: false,
  1898. dataType: 'json',
  1899. success: function (resp) {
  1900. if (! resp.ok) {
  1901. new Notification('error', 'Import failed: ' + $('<div>').text(resp.error).html(), 6000)
  1902. return
  1903. }
  1904. var notes = []
  1905. if (resp.missingFiles.length > 0) {
  1906. notes.push(resp.missingFiles.length + ' user file' + (resp.missingFiles.length == 1 ? ' is' : 's are')
  1907. + ' missing on this unit: ' + $('<div>').text(resp.missingFiles.slice(0, 5).join(', ')).html()
  1908. + (resp.missingFiles.length > 5 ? ', ...' : ''))
  1909. }
  1910. if (self.isApp && resp.missingPlugins.length > 0) {
  1911. notes.push(resp.missingPlugins.length + ' plugin' + (resp.missingPlugins.length == 1 ? ' is' : 's are')
  1912. + ' not available on MOD Desktop and will be left out')
  1913. }
  1914. closeWindow()
  1915. self.reset(function () {
  1916. var load = function (ok) {
  1917. if (! ok) {
  1918. self.pedalboard.data('wait').stop()
  1919. return
  1920. }
  1921. $.ajax({
  1922. url: '/pedalboard/file/load/',
  1923. method: 'POST',
  1924. data: { token: resp.token },
  1925. cache: false,
  1926. dataType: 'json',
  1927. success: function (lresp) {
  1928. if (! lresp.ok) {
  1929. self.pedalboard.data('wait').stop()
  1930. new Notification('error', 'Import failed: ' + $('<div>').text(lresp.error).html(), 6000)
  1931. return
  1932. }
  1933. self.pedalboardEmpty = false
  1934. self.setPedalboardAsModified(true)
  1935. var msg = 'Imported "' + $('<div>').text(resp.title).html() + '": save it to add it to your pedalboards'
  1936. if (notes.length > 0) {
  1937. msg += '<br/>' + notes.join('<br/>')
  1938. }
  1939. new Notification(notes.length > 0 ? 'warn' : 'info', msg, 8000)
  1940. },
  1941. error: function () {
  1942. self.pedalboard.data('wait').stop()
  1943. new Bug("Couldn't load the imported pedalboard")
  1944. },
  1945. })
  1946. }
  1947. if (self.isApp || resp.missingPlugins.length == 0) {
  1948. load(true)
  1949. } else {
  1950. self.installMissingPlugins(resp.plugins, load)
  1951. }
  1952. })
  1953. },
  1954. error: function () {
  1955. new Notification('error', 'Import failed: communication failure', 6000)
  1956. },
  1957. })
  1958. }
  1959. Desktop.prototype.loadPedalboard = function (bundlepath, callback) {
  1960. var self = this
  1961. self.reset(function () {
  1962. $.ajax({
  1963. url: '/pedalboard/load_bundle/',
  1964. type: 'POST',
  1965. data: {
  1966. bundlepath: bundlepath
  1967. },
  1968. success: function (resp) {
  1969. if (! resp.ok) {
  1970. callback(false)
  1971. return
  1972. }
  1973. self.title = resp.name
  1974. self.pedalboardBundle = bundlepath
  1975. self.pedalboardEmpty = false
  1976. self.pedalboardDemoPluginsNotified = false
  1977. self.setPedalboardAsModified(false)
  1978. self.titleBox.text(resp.name);
  1979. self.performanceTitleBox.text(resp.name);
  1980. self.titleBox.removeClass("blend");
  1981. callback(true)
  1982. _paq.push(['trackEvent', 'pedalboard', 'pedalboard-load']);
  1983. },
  1984. error: function () {
  1985. new Bug("Couldn't load pedalboard")
  1986. },
  1987. cache: false,
  1988. dataType: 'json'
  1989. })
  1990. })
  1991. }
  1992. Desktop.prototype.saveCurrentPedalboard = function (asNew, callback) {
  1993. var self = this
  1994. if (self.pedalboardEmpty && ! self.pedalboardModified) {
  1995. new Notification('warn', 'Nothing to save', 1500)
  1996. return
  1997. }
  1998. self.saveBox.saveBox('save', "", self.title, asNew,
  1999. function (ok, errorOrPath, title) {
  2000. if (!ok) {
  2001. new Error(errorOrPath)
  2002. return
  2003. }
  2004. if (asNew || title || ! self.title) {
  2005. self.titleBox.removeClass("blend");
  2006. self.previousPedalboardList = null
  2007. }
  2008. self.title = title
  2009. self.pedalboardBundle = errorOrPath
  2010. self.pedalboardEmpty = false
  2011. self.setPedalboardAsModified(false)
  2012. const newTitle = title + " - " + self.pedalboardPresetName
  2013. self.titleBox.text(newTitle)
  2014. self.performanceTitleBox.text(newTitle)
  2015. if (self.previousPedalboardList != null) {
  2016. for (var i=0; i<self.previousPedalboardList.length; i++) {
  2017. var pedal = self.previousPedalboardList[i]
  2018. if (pedal.bundle == self.pedalboardBundle) {
  2019. pedal.version += 1
  2020. break
  2021. }
  2022. }
  2023. }
  2024. new Notification("info", sprintf('Pedalboard "%s" saved', title), 2000)
  2025. if (callback)
  2026. callback()
  2027. })
  2028. }
  2029. Desktop.prototype.shareCurrentPedalboard = function (callback) {
  2030. $('#pedalboard-sharing .button').click()
  2031. }
  2032. Desktop.prototype.openPresetSaveWindow = function (windowTitle, name, callback) {
  2033. this.presetSaveBox.saveBox('save', windowTitle, name, true,
  2034. function (ok, ignored, newName) {
  2035. callback(newName)
  2036. })
  2037. }
  2038. Desktop.prototype.getDeviceShopToken = function(callback) {
  2039. var self = this;
  2040. var getToken = function() {
  2041. $.ajax({
  2042. url: SITEURL + '/licenses/requests/',
  2043. cache: false,
  2044. method: 'GET',
  2045. headers: {
  2046. 'Authorization' : 'MOD ' + self.cloudAccessToken
  2047. },
  2048. success: function(result) {
  2049. callback(result.id);
  2050. },
  2051. error: function(result) {
  2052. new Notification('error', "Cannot get transaction authorization from Cloud, please contact support", 10000);
  2053. }
  2054. });
  2055. }
  2056. if (self.cloudAccessToken == null) {
  2057. desktop.authenticateDevice(function (ok) {
  2058. if (ok && self.cloudAccessToken != null) {
  2059. getToken()
  2060. } else {
  2061. new Notification('error', "Can't authenticate with Cloud to access plugin store", 5000)
  2062. }
  2063. })
  2064. } else {
  2065. getToken();
  2066. }
  2067. }
  2068. // TODO cache
  2069. Desktop.prototype.fetchShopProducts = function() {
  2070. var self = this
  2071. return new Promise(function(resolve, reject) {
  2072. var shopClient = ShopifyBuy.buildClient(SHOPIFY_CLIENT_OPTIONS);
  2073. shopClient.fetchAllProducts().then(function(products) {
  2074. if (products.length > 0) {
  2075. self.createCart(shopClient)
  2076. }
  2077. resolve(products)
  2078. }, reject)
  2079. })
  2080. }
  2081. Desktop.prototype.fetchShopProduct = function(uri) {
  2082. var self = this
  2083. var shopClient = ShopifyBuy.buildClient(SHOPIFY_CLIENT_OPTIONS);
  2084. // TODO would be more efficient to query one single product,
  2085. // but don't know how to query by variant's SKU
  2086. return shopClient.fetchAllProducts().then(function(products) {
  2087. for (var i in products) {
  2088. if (uri == products[i].selectedVariant.attrs.variant.sku) {
  2089. self.createCart(shopClient)
  2090. return products[i]
  2091. }
  2092. }
  2093. })
  2094. }
  2095. Desktop.prototype.createCart = function(shopClient) {
  2096. var self = this
  2097. ShopifyBuy.UI.onReady(shopClient).then(function (ui) {
  2098. ui.createComponent('cart', {
  2099. moneyFormat: '%E2%82%AC%7B%7Bamount%7D%7D',
  2100. options: SHOPIFY_PRODUCT_OPTIONS
  2101. }).then(function(cart) {
  2102. self.cart = cart;
  2103. })
  2104. self.windowManager.registerShopify(ui);
  2105. })
  2106. }
  2107. Desktop.prototype.createBuyButton = function(shopifyId) {
  2108. var shopClient = ShopifyBuy.buildClient(SHOPIFY_CLIENT_OPTIONS);
  2109. ShopifyBuy.UI.onReady(shopClient).then(function (ui) {
  2110. var node = document.getElementById('product-component-'+shopifyId);
  2111. var button = $('<div class="shopify-fake-button">ADD TO CART</div>').appendTo(node);
  2112. ui.createComponent('product', {
  2113. id: [shopifyId],
  2114. node: node,
  2115. moneyFormat: '%E2%82%AC%7B%7Bamount%7D%7D',
  2116. options: SHOPIFY_PRODUCT_OPTIONS
  2117. });
  2118. });
  2119. }
  2120. Desktop.prototype.waitForLicenses = function(deviceToken) {
  2121. var self = this;
  2122. var poll = function() {
  2123. $.ajax({
  2124. url: SITEURL + '/licenses/requests/'+deviceToken,
  2125. method: 'GET',
  2126. headers: {
  2127. 'Authorization' : 'MOD ' + self.cloudAccessToken
  2128. },
  2129. success: function(result) {
  2130. if (self.licenseManager === null || !result.fulfilled) {
  2131. setTimeout(poll, 5000);
  2132. return;
  2133. }
  2134. self.licenseManager.addLicenses(result.license_info, function() {
  2135. var s = result.license_info.length > 1 ? 's' : ''
  2136. var msg = result.license_info.length + ' new plugin'+s+' purchased'
  2137. new Notification('info', msg);
  2138. var uris = result.license_info.map(function(l) { return l.plugin_uri });
  2139. if (self.cart) {
  2140. self.cart.empty()
  2141. self.cart.close()
  2142. }
  2143. })
  2144. },
  2145. error: function() {
  2146. new Notification('error', "Can't get licenses from Cloud, please reload interface after finishing your purchase");
  2147. }
  2148. });
  2149. }
  2150. setTimeout(poll, 5000);
  2151. }
  2152. Desktop.prototype.license = function(uri) {
  2153. var container = $('[mod-uri="'+escape(uri)+'"]')
  2154. container.find('.price').removeClass('price').addClass('licensed').html('')
  2155. container.find('.description-price').removeClass('description-price').addClass('description-licensed').html('')
  2156. container.find('.demo-mask').remove()
  2157. container.find('.buy-button').remove()
  2158. container.find('button').each(function(index, button) {
  2159. $(button).html($(button).html().replace(/\s+Trial/, ''))
  2160. });
  2161. this.pedalboard.pedalboard('license', uri)
  2162. }
  2163. /*
  2164. * Ask user for a text input
  2165. * windowTitle: title of the window
  2166. * value: default value
  2167. * callback: function(newValue) called when user clicks ok
  2168. * okLabel: label of the ok button (default: 'Ok')
  2169. */
  2170. Desktop.prototype.openInputBoxWindow = function (windowTitle, value, callback, okLabel, validateCallback) {
  2171. this.inputBox.inputBox('show', windowTitle, value, callback, okLabel, validateCallback)
  2172. }
  2173. JqueryClass('inputBox', {
  2174. init: function (options) {
  2175. var self = $(this)
  2176. options = $.extend({
  2177. }, options)
  2178. self.data(options)
  2179. self.data('disabled', false)
  2180. var done = function () {
  2181. // call the user callback
  2182. self.inputBox('_onResult', false)
  2183. return false
  2184. }
  2185. self.find('.js-done').click(done).prop('disabled',true)
  2186. self.find('.js-cancel').click(function () {
  2187. if (self.data('disabled')) {
  2188. return false
  2189. }
  2190. self.inputBox('_onResult', true)
  2191. self.hide()
  2192. return false
  2193. })
  2194. self.find('input').keyup(function () {
  2195. var value = self.find('input').val()
  2196. const isValid = self.inputBox('_validate', value)
  2197. self.find('.js-done').prop('disabled', isValid ? false : true);
  2198. })
  2199. self.keydown(function (e) {
  2200. if (self.data('disabled')) {
  2201. return false
  2202. }
  2203. if (e.keyCode == 13) {
  2204. return done()
  2205. }
  2206. if (e.keyCode == 27) {
  2207. self.inputBox('_onResult', true)
  2208. self.hide()
  2209. return false
  2210. }
  2211. })
  2212. return self
  2213. },
  2214. /*
  2215. * Show the input box
  2216. * windowTitle: title of the window
  2217. * value: default value
  2218. * callback: function(newValue) called when user clicks ok
  2219. * okLabel: label of the ok button (default: 'Ok')
  2220. * isValidCallback: optional function(newValue) called when user changes the text, should return true if the value is valid
  2221. */
  2222. show: function (windowTitle, value, callback, okLabel, isValidCallback) {
  2223. var self = $(this)
  2224. if (!okLabel) {
  2225. okLabel = 'Save'
  2226. }
  2227. var saveButton = self.find('.js-done')
  2228. saveButton.text(okLabel)
  2229. self.find('input').val(value)
  2230. self.data('callback', callback)
  2231. self.data('isValidCallback', isValidCallback)
  2232. if (windowTitle) {
  2233. self.find('h1').text(windowTitle)
  2234. }
  2235. self.show()
  2236. self.focus()
  2237. const input = self.find('input')
  2238. input.focus(function() { $(this).select(); } )
  2239. input.focus()
  2240. },
  2241. _validate: function (value) {
  2242. var self = $(this)
  2243. const isValidCallback = self.data('isValidCallback')
  2244. let isValid = true
  2245. if (isValidCallback) {
  2246. isValid = isValidCallback(value)
  2247. } else {
  2248. // default validation: non empty
  2249. isValid = value && value.length > 0
  2250. }
  2251. return isValid
  2252. },
  2253. _onResult: function (cancelled) {
  2254. var self = $(this)
  2255. var newValue = self.find('input').val()
  2256. if (!cancelled) {
  2257. if (!self.inputBox('_validate', newValue)) {
  2258. new Bug("Input not valid")
  2259. return
  2260. }
  2261. }
  2262. self.data('disabled', true)
  2263. self.find('.js-cancel').prop('disabled', true)
  2264. self.find('.js-done').prop('disabled', true)
  2265. let returnValue = undefined
  2266. try {
  2267. returnValue = self.data('callback')(newValue, cancelled)
  2268. } catch (e) {
  2269. console.warn('Input box callback failed:', e)
  2270. }
  2271. if (returnValue !== false) {
  2272. self.hide()
  2273. }
  2274. self.data('disabled', false)
  2275. self.find('.js-cancel').prop('disabled', false)
  2276. self.find('.js-done').prop('disabled', false)
  2277. return
  2278. }
  2279. })
  2280. JqueryClass('saveBox', {
  2281. init: function (options) {
  2282. var self = $(this)
  2283. options = $.extend({
  2284. save: function (windowTitle, name, asNew, callback) {
  2285. callback(false, "Not Implemented")
  2286. }
  2287. }, options)
  2288. self.data(options)
  2289. self.data('disabled', false)
  2290. var save = function () {
  2291. self.saveBox('send')
  2292. return false
  2293. }
  2294. self.find('.js-save').click(save).prop('disabled',true)
  2295. self.find('.js-cancel-saving').click(function () {
  2296. if (self.data('disabled')) {
  2297. return false
  2298. }
  2299. self.hide()
  2300. return false
  2301. })
  2302. self.find('input').keyup(function () {
  2303. self.find('.js-save').prop('disabled', this.value.length == 0 ? true : false);
  2304. })
  2305. self.keydown(function (e) {
  2306. if (self.data('disabled')) {
  2307. return false
  2308. }
  2309. if (e.keyCode == 13) {
  2310. return save()
  2311. }
  2312. if (e.keyCode == 27) {
  2313. self.hide()
  2314. return false
  2315. }
  2316. })
  2317. return self
  2318. },
  2319. save: function (windowTitle, name, asNew, callback) {
  2320. var self = $(this)
  2321. self.find('input').val(name)
  2322. self.data('asNew', asNew)
  2323. self.data('callback', callback)
  2324. if (windowTitle) {
  2325. self.find('h1').text(windowTitle)
  2326. }
  2327. if (name && !asNew) {
  2328. self.saveBox('send')
  2329. } else {
  2330. self.saveBox('edit')
  2331. }
  2332. },
  2333. edit: function () {
  2334. var self = $(this)
  2335. self.find('.js-save').prop('disabled', self.find('input').val().length == 0 ? true : false);
  2336. self.show()
  2337. self.focus()
  2338. self.find('input').focus()
  2339. },
  2340. send: function () {
  2341. var self = $(this)
  2342. var title = self.find('input').val()
  2343. var asNew = self.data('asNew')
  2344. if (title.length == 0) {
  2345. new Bug("Cannot save with an empty name!")
  2346. return
  2347. }
  2348. self.data('disabled', true)
  2349. self.find('.js-cancel-saving').prop('disabled', true)
  2350. self.find('.js-save').prop('disabled', true)
  2351. self.data('save')("", title, asNew,
  2352. function (ok, errorOrPath, realTitle) {
  2353. if (! ok) {
  2354. new Bug(errorOrPath)
  2355. }
  2356. self.hide()
  2357. self.data('disabled', false)
  2358. self.find('.js-cancel-saving').prop('disabled', false)
  2359. self.find('.js-save').prop('disabled', false)
  2360. self.data('callback')(true, errorOrPath, realTitle)
  2361. })
  2362. return
  2363. }
  2364. })
  2365. JqueryClass('statusTooltip', {
  2366. init: function () {
  2367. var self = $(this)
  2368. var tooltip = $('<div class="tooltip">').appendTo($('body'))
  2369. tooltip.data('arrow', $('<div class="arrow">').appendTo(tooltip))
  2370. $('<div class="text">').appendTo(tooltip)
  2371. tooltip.hide()
  2372. self.data('tooltip', tooltip)
  2373. self.bind('mouseover', function () {
  2374. self.statusTooltip('showTooltip')
  2375. })
  2376. self.bind('mouseout', function () {
  2377. tooltip.stop().animate({
  2378. opacity: 0
  2379. }, 200,
  2380. function () {
  2381. $(this).hide()
  2382. })
  2383. })
  2384. // Special case for bottom left mod-plugins icon
  2385. // arrow should be on the left, not on the right
  2386. if (self.attr('id') === "mod-plugins") {
  2387. var arrow = tooltip.data('arrow');
  2388. arrow.css('left', 14);
  2389. }
  2390. return self
  2391. },
  2392. status: function (status) {
  2393. var self = $(this)
  2394. if (self.data('status'))
  2395. self.removeClass(self.data('status'))
  2396. self.data('status', status)
  2397. self.addClass(status)
  2398. },
  2399. message: function (message, silent, timeout) {
  2400. var self = $(this)
  2401. var oldMsg = self.data('message')
  2402. self.data('message', message)
  2403. if (!silent && oldMsg != message)
  2404. self.statusTooltip('showTooltip', timeout || 1500)
  2405. },
  2406. showTooltip: function (timeout) {
  2407. var self = $(this)
  2408. var msg = self.data('message')
  2409. if (!msg)
  2410. return
  2411. var tooltip = self.data('tooltip')
  2412. tooltip.find('.text').html(self.data('message'))
  2413. tooltip.show().stop().animate({
  2414. opacity: 1
  2415. }, 200)
  2416. // Adjust tooltip position in case window has been resized
  2417. self.statusTooltip('updatePosition')
  2418. if (timeout) {
  2419. setTimeout(function () {
  2420. tooltip.stop().animate({
  2421. opacity: 0
  2422. }, 200,
  2423. function () {
  2424. $(this).hide()
  2425. })
  2426. }, timeout)
  2427. }
  2428. },
  2429. updatePosition: function() {
  2430. var self = $(this)
  2431. var tooltip = self.data('tooltip')
  2432. tooltip.css('right', $(window).width() - self.position().left - self.width())
  2433. // Special case for bottom left mod-plugins icon
  2434. if (self.attr('id') === "mod-plugins") {
  2435. tooltip.css('right', $(window).width() - self.position().left - self.width() + tooltip.position().left);
  2436. }
  2437. }
  2438. })
  2439. // Tools for developers and beta testers, each switched on its own in Settings > User Interface.
  2440. // A tool never set on its own follows the old "dev-mode" switch, so units that had Developer Mode on keep everything.
  2441. // Install All and Update All were one switch ("ui-store-all") before they got one each; that value is their default.
  2442. var UI_TOOLS = ['ui-xruns', 'ui-buffersize', 'ui-cpu-stats', 'ui-ping-times', 'ui-store-install-all', 'ui-store-update-all', 'ui-share']
  2443. var UI_TOOL_FALLBACK = {
  2444. 'ui-store-install-all': 'ui-store-all',
  2445. 'ui-store-update-all': 'ui-store-all',
  2446. }
  2447. function ui_tool_value(key) {
  2448. var value = PREFERENCES[key]
  2449. if (value !== "on" && value !== "off" && UI_TOOL_FALLBACK[key]) {
  2450. value = PREFERENCES[UI_TOOL_FALLBACK[key]]
  2451. }
  2452. if (value !== "on" && value !== "off") {
  2453. value = PREFERENCES['dev-mode']
  2454. }
  2455. return value
  2456. }
  2457. function ui_tool_enabled(key) {
  2458. return ui_tool_value(key) == "on"
  2459. }
  2460. function apply_ui_tools() {
  2461. var toggle = function (selector, enabled) {
  2462. if (enabled) {
  2463. $(selector).show()
  2464. } else {
  2465. $(selector).hide()
  2466. }
  2467. }
  2468. // install all / update all plugins, one switch each
  2469. toggle('#cloud_install_all', ui_tool_enabled('ui-store-install-all'))
  2470. toggle('#cloud_update_all', ui_tool_enabled('ui-store-update-all'))
  2471. // network and controller ping times
  2472. toggle('#mod-status', ui_tool_enabled('ui-ping-times'))
  2473. // xrun counter
  2474. toggle('#mod-xruns', ui_tool_enabled('ui-xruns'))
  2475. // buffer size button
  2476. toggle('#mod-buffersize', ui_tool_enabled('ui-buffersize'))
  2477. // CPU speed and temperature, not available on the Duo
  2478. toggle('#mod-cpu-stats', ui_tool_enabled('ui-cpu-stats') && PLATFORM != "duo")
  2479. // preset and pedalboard Export / Import buttons (MOD Desktop always shows them)
  2480. if (ui_tool_enabled('ui-share') || USING_MOD_DESKTOP) {
  2481. $('body').addClass('preset-share pedalboard-share')
  2482. } else {
  2483. $('body').removeClass('preset-share pedalboard-share')
  2484. }
  2485. // the status bar items moved: adjust the tooltips and the transport window
  2486. if (ui_tool_enabled('ui-ping-times')) {
  2487. $('#mod-status').statusTooltip('updatePosition')
  2488. }
  2489. $('#mod-devices').statusTooltip('updatePosition')
  2490. $('#mod-settings').statusTooltip('updatePosition')
  2491. // the transport window opens above its icon; the items on its right push the icon to the left
  2492. var transportRight = 310
  2493. $('#mod-status, #mod-cpu-stats, #mod-xruns, #mod-buffersize').each(function () {
  2494. if ($(this).is(':visible')) {
  2495. transportRight += $(this).outerWidth(true)
  2496. }
  2497. })
  2498. $('#mod-transport-window').css({
  2499. right: transportRight + 'px'
  2500. })
  2501. }
  2502. // Console helpers, kept from the old Developer Mode: switch every tool on or off at once.
  2503. function set_all_ui_tools(value) {
  2504. for (var i in UI_TOOLS) {
  2505. PREFERENCES[UI_TOOLS[i]] = value
  2506. desktop.saveConfigValue(UI_TOOLS[i], value)
  2507. }
  2508. PREFERENCES['dev-mode'] = value
  2509. desktop.saveConfigValue("dev-mode", value)
  2510. apply_ui_tools()
  2511. }
  2512. function enable_dev_mode() {
  2513. set_all_ui_tools("on")
  2514. return "Dev mode enabled!"
  2515. }
  2516. function disable_dev_mode() {
  2517. set_all_ui_tools("off")
  2518. return "Dev mode disabled!"
  2519. }