├── .browserslistrc ├── .dockerignore ├── .editorconfig ├── .eslintrc.js ├── .github ├── FUNDING.yml ├── dependabot.yml ├── noisedash-screenshot-1.jpg ├── noisedash-screenshot-2.jpg ├── noisedash-screenshot-3.jpg ├── noisedash-screenshot-4.png ├── noisedash-screenshot-mobile-1.png └── workflows │ └── docker-image.yml ├── .gitignore ├── CONTRIBUTING.md ├── Dockerfile ├── LICENSE ├── README.md ├── babel.config.js ├── config ├── default.json └── production.json ├── docker-compose.yml ├── kubernetes └── manifest.yaml ├── package-lock.json ├── package.json ├── public ├── favicon.ico └── index.html ├── server ├── app.js ├── bin │ └── www.js ├── boot │ ├── auth.js │ └── db.js ├── db.js ├── logger.js └── routes │ ├── auth.js │ ├── profiles.js │ ├── samples.js │ └── users.js ├── src ├── App.vue ├── assets │ ├── logo.png │ └── logo.svg ├── axios.js ├── components │ ├── AccountPage.vue │ ├── AdminPage.vue │ ├── AppBar.vue │ ├── LoginPage.vue │ ├── NoisePage.vue │ ├── RegisterPage.vue │ ├── account.js │ ├── admin.js │ ├── appbar.js │ ├── login.js │ ├── noise.js │ └── register.js ├── main.js ├── plugins │ └── vuetify.js ├── router │ └── index.js └── views │ ├── AccountView.vue │ ├── AdminView.vue │ ├── HomeView.vue │ ├── LoginView.vue │ └── RegisterView.vue └── vue.config.js /.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | not dead 4 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | dist 2 | log 3 | node_modules 4 | samples 5 | sessions 6 | db 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{js,jsx,ts,tsx,vue}] 2 | indent_style = space 3 | indent_size = 2 4 | trim_trailing_whitespace = true 5 | insert_final_newline = true 6 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true 5 | }, 6 | extends: [ 7 | 'plugin:vue/recommended', 8 | '@vue/standard' 9 | ], 10 | parserOptions: { 11 | parser: '@babel/eslint-parser' 12 | }, 13 | rules: { 14 | 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 15 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 16 | 'prefer-arrow-callback': 'error' 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: kaythomas0 4 | custom: "https://kaythomas.dev/cryptocurrency.html" 5 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "npm" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | # Disable version updates for npm dependencies 8 | open-pull-requests-limit: 0 9 | -------------------------------------------------------------------------------- /.github/noisedash-screenshot-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaythomas0/noisedash/99857c7a0d379df2128fbd281bee684c7c2d2ce2/.github/noisedash-screenshot-1.jpg -------------------------------------------------------------------------------- /.github/noisedash-screenshot-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaythomas0/noisedash/99857c7a0d379df2128fbd281bee684c7c2d2ce2/.github/noisedash-screenshot-2.jpg -------------------------------------------------------------------------------- /.github/noisedash-screenshot-3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaythomas0/noisedash/99857c7a0d379df2128fbd281bee684c7c2d2ce2/.github/noisedash-screenshot-3.jpg -------------------------------------------------------------------------------- /.github/noisedash-screenshot-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaythomas0/noisedash/99857c7a0d379df2128fbd281bee684c7c2d2ce2/.github/noisedash-screenshot-4.png -------------------------------------------------------------------------------- /.github/noisedash-screenshot-mobile-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaythomas0/noisedash/99857c7a0d379df2128fbd281bee684c7c2d2ce2/.github/noisedash-screenshot-mobile-1.png -------------------------------------------------------------------------------- /.github/workflows/docker-image.yml: -------------------------------------------------------------------------------- 1 | name: Docker Image CI 2 | 3 | on: 4 | pull_request: 5 | types: 6 | - labeled 7 | branches: 8 | - 'main' 9 | 10 | jobs: 11 | buildx: 12 | if: ${{ github.event.label.name == 'run-workflow' }} 13 | runs-on: ubuntu-latest 14 | steps: 15 | - 16 | name: Checkout 17 | uses: actions/checkout@v3 18 | - 19 | name: Set up QEMU 20 | uses: docker/setup-qemu-action@v1 21 | - 22 | name: Set up Docker Buildx 23 | id: buildx 24 | uses: docker/setup-buildx-action@v1 25 | - 26 | name: Login to DockerHub 27 | uses: docker/login-action@v1 28 | with: 29 | username: ${{ secrets.DOCKERHUB_USERNAME }} 30 | password: ${{ secrets.DOCKERHUB_TOKEN }} 31 | - 32 | name: Build and push 33 | uses: docker/build-push-action@v2 34 | with: 35 | context: . 36 | platforms: linux/amd64,linux/arm/v7,linux/arm64 37 | push: true 38 | tags: noisedash/noisedash:latest,noisedash/noisedash:${{ github.head_ref }} 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | # Local dev certs 107 | certs/* 108 | 109 | # SQLite DB 110 | db.sqlite3 111 | 112 | # Sessions file store 113 | sessions/* 114 | 115 | # Samples 116 | samples/* 117 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Project setup 2 | Requires [Node](https://nodejs.org/en/download/) and [Vue CLI](https://cli.vuejs.org/guide/installation.html) 3 | 4 | ``` 5 | npm install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | npm run serve 11 | ``` 12 | 13 | ### Runs the server 14 | ``` 15 | npm run server 16 | ``` 17 | 18 | ### Compiles and minifies for production 19 | ``` 20 | npm run build 21 | ``` 22 | 23 | ### Lints and fixes files 24 | ``` 25 | npm run lint 26 | ``` 27 | 28 | ### Directory Summary 29 | 30 | Here are some of the more important files and directories: 31 | 32 | * `config/default.json`: Contains the default configuration file 33 | * `server/*`: Where all of the node server related code is 34 | * `server/app.js`: The main server file where server settings are set 35 | * `server/db.js`: Where the database is created 36 | * `server/logger.js`: Where the logger is created and configured 37 | * `server/bin/www.js`: The entry point of the server application (what you run to start the server) 38 | * `server/boot/*`: These are run on server startup 39 | * `server/routes/*`: Where all of the server routes and logic are defined 40 | * `src/*`: Contains all the frontend code 41 | * `src/components/*`: Where all of the Vue components are defined, split into vue and js files for each component 42 | * `src/router/index.js`: Where all the routing and route-protection logic is defined 43 | * `src/views/*`: Contains all the views 44 | 45 | ### Customize configuration 46 | See [Configuration Reference](https://cli.vuejs.org/config/). 47 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:16 2 | LABEL maintainer="kaythomas@pm.me" 3 | WORKDIR /var/noisedash 4 | COPY package*.json ./ 5 | RUN npm install --force 6 | COPY . . 7 | ENV NODE_ENV production 8 | RUN npm run build 9 | EXPOSE 1432 10 | CMD [ "node", "server/bin/www.js" ] 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Noisedash 2 | 3 | Self-hostable web tool for generating ambient noises 4 | 5 | ![Noisedash](https://raw.githubusercontent.com/kaythomas0/noisedash/dev/.github/noisedash-screenshot-1.jpg) 6 | 7 | (More screenshots on the [wiki](https://github.com/kaythomas0/noisedash/wiki/Screenshots)) 8 | 9 | # Features 10 | 11 | * Generate and customize ambient noises and user-uploadable samples (leveraging [Tone.js](https://github.com/Tonejs/Tone.js/)) 12 | * Save "noise profiles" so you can easily switch between your created soundscapes. Import and export them for easy sharing, record them for use elsewhere 13 | * Fine-tune your noises with audio processing tools like filters, LFOs, and effects 14 | * Upload and edit audio samples (e.g rain, wind, thunder) to combine with your generated noises. Add effects to them and set playback modes 15 | * Use admin tools to manage multiple users 16 | * Mobile friendly 17 | 18 | # Installation 19 | 20 | ## Docker 21 | 22 | Requires docker and docker-compose 23 | 24 | * Download the provided [docker-compose.yml file](https://github.com/kaythomas0/noisedash/blob/main/docker-compose.yml) 25 | * In the same directory as the docker-compose file, created a folder called `config`, and inside it, put the provided [config file](https://github.com/kaythomas0/noisedash/blob/main/config/default.json) 26 | * Edit the config file to your preference 27 | * Bring the container up: 28 | 29 | ``` bash 30 | docker-compose up -d 31 | ``` 32 | 33 | * Proceed to the URL where it's deployed and register your first user 34 | 35 | (Raspberry Pi compatible images are available, see armv7 images on [Docker Hub](https://hub.docker.com/repository/docker/noisedash/noisedash)) 36 | 37 | ## Kubernetes 38 | 39 | You can apply the manifest.yaml in the kubernetes folder to install Noisedash into your Kubernetes cluster. 40 | 41 | Optionally, uncomment the last lines in the file to also create an ingress. The ingress, commented out by default, needs to have the clusterIssuser annotation set to your cluster issuer (default: letsencrypt-prod) and the ingress class set to your Ingress class (default: Nginx) 42 | 43 | 44 | ``` bash 45 | $ kubectl apply -f ./kubernetes/manifest.yaml 46 | persistentvolumeclaim/db-pvc created 47 | persistentvolumeclaim/samples-pvc created 48 | deployment.apps/noisedash created 49 | service/noisedash created 50 | configmap/noisedashcfg created 51 | ingress.networking.k8s.io/noisedashingress created 52 | ``` 53 | 54 | ## From Source 55 | 56 | Requires node 16 and npm 57 | 58 | * Clone the repo: 59 | 60 | ``` bash 61 | git clone https://github.com/kaythomas0/noisedash.git 62 | cd noisedash 63 | ``` 64 | 65 | * Edit `config/default.json` to your preference 66 | * Install required packages and build the app: 67 | 68 | ``` bash 69 | npm install 70 | NODE_ENV=production npm run build 71 | ``` 72 | 73 | * The build files will be put into a directory called `dist` 74 | * Run the server and serve static files: 75 | 76 | ``` bash 77 | npm run server-prod 78 | ``` 79 | 80 | * Proceed to the URL where it's deployed and register your first user 81 | 82 | # Contributing 83 | 84 | See [CONTRIBUTING.md](https://github.com/kaythomas0/noisedash/blob/main/CONTRIBUTING.md) 85 | 86 | # License 87 | 88 | Noisedash, a self-hostable web tool for generating ambient noises 89 | Copyright (C) 2021 Kay Thomas 90 | 91 | This program is free software: you can redistribute it and/or modify 92 | it under the terms of the GNU Affero General Public License as published 93 | by the Free Software Foundation, either version 3 of the License, or 94 | (at your option) any later version. 95 | 96 | This program is distributed in the hope that it will be useful, 97 | but WITHOUT ANY WARRANTY; without even the implied warranty of 98 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 99 | GNU Affero General Public License for more details. 100 | 101 | You should have received a copy of the GNU Affero General Public License 102 | along with this program. If not, see . 103 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /config/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "Server": { 3 | "listeningPort": 1432, 4 | "sessionFileStorePath": "sessions", 5 | "sampleUploadPath": "samples", 6 | "maxSampleSize": 10737418240, // In bytes, 10GB by default 7 | "logFile": "log/noisedash.log", 8 | "tls": false, // Keep this as false if using an external web server like nginx 9 | "tlsKey": "certs/key.pem", 10 | "tlsCert": "certs/cert.pem" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /config/production.json: -------------------------------------------------------------------------------- 1 | {} // Left empty intentionally: https://github.com/node-config/node-config/wiki/Strict-Mode#node_env-value-of-node_env-did-not-match-any-deployment-config-file-names= -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | noisedash: 5 | image: noisedash/noisedash:latest 6 | container_name: noisedash 7 | ports: 8 | - "1432:1432" 9 | volumes: 10 | - db:/var/noisedash/db 11 | - samples:/var/noisedash/samples 12 | - ./config/default.json:/var/noisedash/config/default.json 13 | 14 | volumes: 15 | db: 16 | samples: 17 | 18 | -------------------------------------------------------------------------------- /kubernetes/manifest.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: PersistentVolumeClaim 3 | metadata: 4 | name: db-pvc 5 | spec: 6 | accessModes: 7 | - ReadWriteOnce 8 | resources: 9 | requests: 10 | storage: 10Gi 11 | --- 12 | apiVersion: v1 13 | kind: PersistentVolumeClaim 14 | metadata: 15 | name: samples-pvc 16 | spec: 17 | accessModes: 18 | - ReadWriteOnce 19 | resources: 20 | requests: 21 | storage: 10Gi 22 | --- 23 | apiVersion: apps/v1 24 | kind: Deployment 25 | metadata: 26 | name: noisedash 27 | spec: 28 | replicas: 1 29 | selector: 30 | matchLabels: 31 | app: noisedash 32 | template: 33 | metadata: 34 | labels: 35 | app: noisedash 36 | spec: 37 | containers: 38 | - name: noisedash 39 | image: noisedash/noisedash:latest 40 | ports: 41 | - containerPort: 1432 42 | volumeMounts: 43 | - name: db 44 | mountPath: /var/noisedash/db 45 | - name: samples 46 | mountPath: /var/noisedash/samples 47 | - name: config 48 | mountPath: /var/noisedash/config/default.json 49 | subPath: config.json 50 | volumes: 51 | - name: db 52 | persistentVolumeClaim: 53 | claimName: db-pvc 54 | - name: samples 55 | persistentVolumeClaim: 56 | claimName: samples-pvc 57 | - name: config 58 | configMap: 59 | name: noisedashcfg 60 | --- 61 | apiVersion: v1 62 | kind: Service 63 | metadata: 64 | name: noisedash 65 | spec: 66 | selector: 67 | app: noisedash 68 | ports: 69 | - protocol: TCP 70 | port: 80 71 | targetPort: 1432 72 | --- 73 | apiVersion: v1 74 | kind: ConfigMap 75 | metadata: 76 | name: noisedashcfg 77 | data: 78 | config.json: | 79 | { 80 | "Server": { 81 | "listeningPort": 1432, 82 | "sessionFileStorePath": "sessions", 83 | "sampleUploadPath": "samples", 84 | "maxSampleSize": 10737418240, 85 | "logFile": "log/noisedash.log", 86 | "tls": false, 87 | "tlsKey": "certs/key.pem", 88 | "tlsCert": "certs/cert.pem" 89 | } 90 | } 91 | --- 92 | apiVersion: networking.k8s.io/v1 93 | kind: Ingress 94 | metadata: 95 | annotations: 96 | cert-manager.io/cluster-issuer: letsencrypt-prod 97 | kubernetes.io/ingress.class: nginx 98 | kubernetes.io/tls-acme: "true" 99 | nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" 100 | nginx.ingress.kubernetes.io/proxy-send-timeout: "3600" 101 | labels: 102 | app.kubernetes.io/instance: noisedash 103 | name: noisedashingress 104 | spec: 105 | rules: 106 | - host: noisedash.freshbrewed.science 107 | http: 108 | paths: 109 | - backend: 110 | service: 111 | name: noisedash 112 | port: 113 | number: 80 114 | path: / 115 | pathType: ImplementationSpecific 116 | tls: 117 | - hosts: 118 | - noisedash.freshbrewed.science 119 | secretName: noisedash-tls 120 | builder@DESKTOP-QADGF36:~/Workspaces/pyplanereport$ 121 | builder@DESKTOP-QADGF36:~/Workspaces/pyplanereport$ cat noiseall.yaml 122 | apiVersion: v1 123 | kind: PersistentVolumeClaim 124 | metadata: 125 | name: db-pvc 126 | spec: 127 | accessModes: 128 | - ReadWriteOnce 129 | resources: 130 | requests: 131 | storage: 10Gi 132 | --- 133 | apiVersion: v1 134 | kind: PersistentVolumeClaim 135 | metadata: 136 | name: samples-pvc 137 | spec: 138 | accessModes: 139 | - ReadWriteOnce 140 | resources: 141 | requests: 142 | storage: 10Gi 143 | --- 144 | apiVersion: apps/v1 145 | kind: Deployment 146 | metadata: 147 | name: noisedash 148 | spec: 149 | replicas: 1 150 | selector: 151 | matchLabels: 152 | app: noisedash 153 | template: 154 | metadata: 155 | labels: 156 | app: noisedash 157 | spec: 158 | containers: 159 | - name: noisedash 160 | image: noisedash/noisedash:latest 161 | ports: 162 | - containerPort: 1432 163 | volumeMounts: 164 | - name: db 165 | mountPath: /var/noisedash/db 166 | - name: samples 167 | mountPath: /var/noisedash/samples 168 | - name: config 169 | mountPath: /var/noisedash/config/default.json 170 | subPath: config.json 171 | volumes: 172 | - name: db 173 | persistentVolumeClaim: 174 | claimName: db-pvc 175 | - name: samples 176 | persistentVolumeClaim: 177 | claimName: samples-pvc 178 | - name: config 179 | configMap: 180 | name: noisedashcfg 181 | --- 182 | apiVersion: v1 183 | kind: Service 184 | metadata: 185 | name: noisedash 186 | spec: 187 | selector: 188 | app: noisedash 189 | ports: 190 | - protocol: TCP 191 | port: 80 192 | targetPort: 1432 193 | --- 194 | apiVersion: v1 195 | kind: ConfigMap 196 | metadata: 197 | name: noisedashcfg 198 | data: 199 | config.json: | 200 | { 201 | "Server": { 202 | "listeningPort": 1432, 203 | "sessionFileStorePath": "sessions", 204 | "sampleUploadPath": "samples", 205 | "maxSampleSize": 10737418240, 206 | "logFile": "log/noisedash.log", 207 | "tls": false, 208 | "tlsKey": "certs/key.pem", 209 | "tlsCert": "certs/cert.pem" 210 | } 211 | } 212 | # --- 213 | # apiVersion: networking.k8s.io/v1 214 | # kind: Ingress 215 | # metadata: 216 | # annotations: 217 | # cert-manager.io/cluster-issuer: letsencrypt-prod 218 | # kubernetes.io/ingress.class: nginx 219 | # kubernetes.io/tls-acme: "true" 220 | # nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" 221 | # nginx.ingress.kubernetes.io/proxy-send-timeout: "3600" 222 | # labels: 223 | # app.kubernetes.io/instance: noisedash 224 | # name: noisedashingress 225 | # spec: 226 | # rules: 227 | # - host: noisedash.freshbrewed.science 228 | # http: 229 | # paths: 230 | # - backend: 231 | # service: 232 | # name: noisedash 233 | # port: 234 | # number: 80 235 | # path: / 236 | # pathType: ImplementationSpecific 237 | # tls: 238 | # - hosts: 239 | # - noisedash.freshbrewed.science 240 | # secretName: noisedash-tls 241 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "noisedash", 3 | "version": "0.6.12", 4 | "private": true, 5 | "author": "Kay Thomas (https://kaythomas.dev)", 6 | "scripts": { 7 | "serve": "vue-cli-service serve", 8 | "build": "vue-cli-service build", 9 | "lint": "vue-cli-service lint", 10 | "server": "node server/bin/www.js", 11 | "server-prod": "NODE_ENV=production node server/bin/www.js" 12 | }, 13 | "dependencies": { 14 | "@vscode/sqlite3": "^5.0.8", 15 | "axios": "^1.6.0", 16 | "config": "^3.3.6", 17 | "connect-history-api-fallback": "^1.6.0", 18 | "cookie-parser": "^1.4.5", 19 | "core-js": "^3.23.5", 20 | "express": "^4.18.1", 21 | "express-session": "^1.17.3", 22 | "multer": "^1.4.5-lts.1", 23 | "passport": "^0.6.0", 24 | "passport-local": "^1.0.0", 25 | "path": "^0.12.7", 26 | "session-file-store": "^1.5.0", 27 | "tone": "^14.7.77", 28 | "vue": "^2.6.11", 29 | "vue-router": "^3.5.4", 30 | "vuetify": "^2.6.10", 31 | "winston": "^3.3.3" 32 | }, 33 | "devDependencies": { 34 | "@babel/core": "^7.12.16", 35 | "@babel/eslint-parser": "^7.12.16", 36 | "@vue/cli-plugin-babel": "^5.0.8", 37 | "@vue/cli-plugin-eslint": "^5.0.8", 38 | "@vue/cli-plugin-router": "^5.0.8", 39 | "@vue/cli-service": "^5.0.8", 40 | "@vue/eslint-config-standard": "^6.1.0", 41 | "eslint": "^7.32.0", 42 | "eslint-plugin-html": "^6.2.0", 43 | "eslint-plugin-import": "^2.25.3", 44 | "eslint-plugin-node": "^11.1.0", 45 | "eslint-plugin-promise": "^5.1.0", 46 | "eslint-plugin-standard": "^4.0.0", 47 | "eslint-plugin-vue": "^8.0.3", 48 | "sass": "~1.32.0", 49 | "sass-loader": "^10.0.0", 50 | "vue-cli-plugin-vuetify": "^2.5.8", 51 | "vue-template-compiler": "^2.6.11", 52 | "vuetify-loader": "^1.7.3" 53 | }, 54 | "bugs": "https://github.com/kaythomas0/noisedash/issues", 55 | "descriptions": "Self-hostable web tool for generating ambient noises", 56 | "homepage": "https://github.com/kaythomas0/noisedash", 57 | "license": "AGPL-3.0-or-later" 58 | } 59 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaythomas0/noisedash/99857c7a0d379df2128fbd281bee684c7c2d2ce2/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 12 | 13 | 16 |
17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /server/app.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const session = require('express-session') 3 | const FileStore = require('session-file-store')(session) 4 | const passport = require('passport') 5 | const path = require('path') 6 | const cookieParser = require('cookie-parser') 7 | const config = require('config') 8 | const history = require('connect-history-api-fallback') 9 | const crypto = require('crypto') 10 | const authRouter = require('./routes/auth') 11 | const usersRouter = require('./routes/users') 12 | const profilesRouter = require('./routes/profiles') 13 | const samplesRouter = require('./routes/samples') 14 | const app = express() 15 | const fileStoreOptions = { 16 | path: config.get('Server.sessionFileStorePath') 17 | } 18 | 19 | require('./boot/db')() 20 | require('./boot/auth')() 21 | 22 | app.use(express.json()) 23 | app.use(express.urlencoded({ extended: false })) 24 | app.use(cookieParser()) 25 | if (process.env.NODE_ENV === 'production') { 26 | app.use(express.static(path.join(__dirname, '../dist'))) 27 | } 28 | 29 | // Workaround for allowing static files to be served while using connect-history-api-fallback 30 | app.use('/samples', express.static(path.join(__dirname, '../', config.get('Server.sampleUploadPath')))) 31 | app.use(history()) 32 | app.use('/samples', express.static(path.join(__dirname, '../', config.get('Server.sampleUploadPath')))) 33 | 34 | const sessionSecret = crypto.randomBytes(64).toString('hex') 35 | app.use(session({ 36 | store: new FileStore(fileStoreOptions), 37 | secret: sessionSecret, 38 | resave: true, 39 | saveUninitialized: true, 40 | cookie: { sameSite: 'strict' } 41 | })) 42 | app.use((req, res, next) => { 43 | const msgs = req.session.messages || [] 44 | res.locals.messages = msgs 45 | res.locals.hasMessages = !!msgs.length 46 | req.session.messages = [] 47 | next() 48 | }) 49 | app.use(passport.initialize()) 50 | app.use(passport.authenticate('session')) 51 | 52 | // Define routes 53 | app.use('/', authRouter) 54 | app.use('/', usersRouter) 55 | app.use('/', profilesRouter) 56 | app.use('/', samplesRouter) 57 | 58 | module.exports = app 59 | -------------------------------------------------------------------------------- /server/bin/www.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const app = require('../app') 4 | const fs = require('fs') 5 | const config = require('config') 6 | const tls = config.get('Server.tls') 7 | const http = require(tls ? 'https' : 'http') 8 | const logger = require('../logger') 9 | 10 | const port = normalizePort(config.get('Server.listeningPort')) 11 | app.set('port', port) 12 | 13 | let server = http.createServer(app) 14 | if (tls) { 15 | const httpsOptions = { 16 | key: fs.readFileSync(config.get('Server.tlsKey')), 17 | cert: fs.readFileSync(config.get('Server.tlsCert')) 18 | } 19 | 20 | server = http.createServer(httpsOptions, app) 21 | } 22 | 23 | server.listen(port) 24 | server.on('error', onError) 25 | server.on('listening', onListening) 26 | 27 | function normalizePort (val) { 28 | const port = parseInt(val, 10) 29 | 30 | if (isNaN(port)) { 31 | // named pipe 32 | return val 33 | } 34 | 35 | if (port >= 0) { 36 | // port number 37 | return port 38 | } 39 | 40 | return false 41 | } 42 | 43 | function onError (error) { 44 | if (error.syscall !== 'listen') { 45 | throw error 46 | } 47 | 48 | const bind = typeof port === 'string' 49 | ? 'Pipe ' + port 50 | : 'Port ' + port 51 | 52 | // handle specific listen errors with friendly messages 53 | switch (error.code) { 54 | case 'EACCES': 55 | logger.error(new Error(bind + ' requires elevated privileges')) 56 | process.exit(1) 57 | case 'EADDRINUSE': 58 | logger.error(new Error(bind + ' is already in use')) 59 | process.exit(1) 60 | default: 61 | throw error 62 | } 63 | } 64 | 65 | function onListening () { 66 | const addr = server.address() 67 | const bind = typeof addr === 'string' 68 | ? 'pipe ' + addr 69 | : 'port ' + addr.port 70 | logger.log('info', 'Listening on %s', bind) 71 | } 72 | -------------------------------------------------------------------------------- /server/boot/auth.js: -------------------------------------------------------------------------------- 1 | const passport = require('passport') 2 | const Strategy = require('passport-local') 3 | const crypto = require('crypto') 4 | const db = require('../db') 5 | 6 | module.exports = function () { 7 | // Configure the local strategy for use by Passport. 8 | // 9 | // The local strategy requires a `verify` function which receives the credentials 10 | // (`username` and `password`) submitted by the user. The function must verify 11 | // that the password is correct and then invoke `cb` with a user object, which 12 | // will be set at `req.user` in route handlers after authentication. 13 | passport.use(new Strategy((username, password, cb) => { 14 | db.get('SELECT rowid AS id, * FROM users WHERE username = ?', [username], (err, row) => { 15 | if (err) { return cb(err) } 16 | if (!row) { return cb(null, false, { message: 'Incorrect username or password.' }) } 17 | 18 | crypto.pbkdf2(password, row.salt, 10000, 32, 'sha256', (err, hashedPassword) => { 19 | if (err) { return cb(err) } 20 | if (!crypto.timingSafeEqual(row.hashed_password, hashedPassword)) { 21 | return cb(null, false, { message: 'Incorrect username or password.' }) 22 | } 23 | 24 | const user = { 25 | id: row.id.toString(), 26 | username: row.username, 27 | displayName: row.name 28 | } 29 | return cb(null, user) 30 | }) 31 | }) 32 | })) 33 | 34 | // Configure Passport authenticated session persistence. 35 | // 36 | // In order to restore authentication state across HTTP requests, Passport needs 37 | // to serialize users into and deserialize users out of the session. The 38 | // typical implementation of this is as simple as supplying the user ID when 39 | // serializing, and querying the user record by ID from the database when 40 | // deserializing. 41 | passport.serializeUser((user, cb) => { 42 | process.nextTick(() => { 43 | cb(null, { id: user.id, username: user.username }) 44 | }) 45 | }) 46 | 47 | passport.deserializeUser((user, cb) => { 48 | process.nextTick(() => { 49 | return cb(null, user) 50 | }) 51 | }) 52 | } 53 | -------------------------------------------------------------------------------- /server/boot/db.js: -------------------------------------------------------------------------------- 1 | const db = require('../db') 2 | const logger = require('../logger') 3 | 4 | module.exports = function () { 5 | db.serialize(() => { 6 | db.run(`CREATE TABLE IF NOT EXISTS users ( 7 | id INTEGER PRIMARY KEY, 8 | username TEXT UNIQUE, 9 | hashed_password BLOB, 10 | salt BLOB, 11 | name TEXT, 12 | is_admin INTEGER, 13 | dark_mode INTEGER, 14 | can_upload INTEGER)` 15 | ) 16 | 17 | db.run(`CREATE TABLE IF NOT EXISTS profiles ( 18 | id INTEGER PRIMARY KEY, 19 | name TEXT, 20 | user INTEGER, 21 | timer_enabled INTEGER, 22 | duration INTEGER, 23 | volume INTEGER, 24 | noise_color TEXT, 25 | filter_enabled INTEGER, 26 | filter_type TEXT, 27 | filter_cutoff INTEGER, 28 | lfo_filter_cutoff_enabled INTEGER, 29 | lfo_filter_cutoff_frequency REAL, 30 | lfo_filter_cutoff_low INTEGER, 31 | lfo_filter_cutoff_high INTEGER, 32 | tremolo_enabled INTEGER, 33 | tremolo_frequency REAL, 34 | tremolo_depth REAL, 35 | FOREIGN KEY(user) REFERENCES users(id), 36 | UNIQUE(user,name))` 37 | ) 38 | 39 | db.run(`CREATE TABLE IF NOT EXISTS samples ( 40 | id INTEGER PRIMARY KEY, 41 | name TEXT, 42 | user INTEGER, 43 | FOREIGN KEY(user) REFERENCES users(id), 44 | UNIQUE(user,name))` 45 | ) 46 | 47 | db.run(`CREATE TABLE IF NOT EXISTS profiles_samples ( 48 | id INTEGER PRIMARY KEY, 49 | profile INTEGER, 50 | sample INTEGER, 51 | volume INTEGER, 52 | FOREIGN KEY(profile) REFERENCES profiles(id), 53 | FOREIGN KEY(sample) REFERENCES samples(id))` 54 | ) 55 | 56 | db.get('PRAGMA user_version', (err, row) => { 57 | if (err) { 58 | logger.error(err) 59 | } else { 60 | const userVersion = row.user_version 61 | 62 | db.serialize(() => { 63 | if (userVersion < 1) { 64 | db.run('ALTER TABLE samples ADD COLUMN fade_in REAL DEFAULT 0') 65 | db.run('ALTER TABLE samples ADD COLUMN loop_points_enabled INTEGER DEFAULT 0') 66 | db.run('ALTER TABLE samples ADD COLUMN loop_start REAL DEFAULT 0') 67 | db.run('ALTER TABLE samples ADD COLUMN loop_end REAL DEFAULT 0') 68 | 69 | db.run('PRAGMA user_version = 1') 70 | } 71 | 72 | if (userVersion < 2) { 73 | db.run('ALTER TABLE users ADD COLUMN preferences TEXT DEFAULT "{}"') 74 | 75 | db.run('PRAGMA user_version = 2') 76 | } 77 | 78 | if (userVersion < 3) { 79 | db.run('ALTER TABLE profiles_samples ADD COLUMN reverb_enabled INTEGER DEFAULT 0') 80 | db.run('ALTER TABLE profiles_samples ADD COLUMN reverb_pre_delay REAL DEFAULT 0') 81 | db.run('ALTER TABLE profiles_samples ADD COLUMN reverb_decay REAL DEFAULT 0') 82 | db.run('ALTER TABLE profiles_samples ADD COLUMN reverb_wet INTEGER DEFAULT 0') 83 | db.run('ALTER TABLE profiles_samples ADD COLUMN playback_mode TEXT DEFAULT "continuous"') 84 | db.run('ALTER TABLE profiles_samples ADD COLUMN sporadic_min INTEGER DEFAULT 30') 85 | db.run('ALTER TABLE profiles_samples ADD COLUMN sporadic_max INTEGER DEFAULT 300') 86 | 87 | db.run('PRAGMA user_version = 3') 88 | } 89 | 90 | if (userVersion < 4) { 91 | db.run('UPDATE users SET preferences = ? WHERE preferences = ?', 92 | ['{"accentColor":{"alpha":1,"hex":"#607D8B","hexa":"#607D8BFF","hsla":{"h":200,"s":18,"l":46,"a":1},"hsva":{"h":200,"s":31,"v":55,"a":1},"hue":200,"rgba":{"r":96,"g":125,"b":139,"a":1}}}', '{}'], 93 | (err) => { 94 | if (err) { 95 | logger.error(err) 96 | } else { 97 | db.run('PRAGMA user_version = 4') 98 | } 99 | }) 100 | } 101 | }) 102 | } 103 | }) 104 | }) 105 | } 106 | -------------------------------------------------------------------------------- /server/db.js: -------------------------------------------------------------------------------- 1 | const sqlite3 = require('@vscode/sqlite3') 2 | const fs = require('fs') 3 | const path = require('path') 4 | 5 | if (!fs.existsSync(path.join(__dirname, '../db'))) { 6 | fs.mkdirSync(path.join(__dirname, '../db')) 7 | } 8 | module.exports = new sqlite3.Database('db/db.sqlite3') 9 | -------------------------------------------------------------------------------- /server/logger.js: -------------------------------------------------------------------------------- 1 | const winston = require('winston') 2 | const config = require('config') 3 | 4 | const logger = winston.createLogger({ 5 | level: 'info', 6 | format: winston.format.combine( 7 | winston.format.timestamp({ 8 | format: 'YYYY-MM-DD HH:mm:ss' 9 | }), 10 | winston.format.errors({ stack: true }), 11 | winston.format.splat(), 12 | winston.format.json() 13 | ), 14 | defaultMeta: { service: 'noisedash' }, 15 | transports: [ 16 | new winston.transports.File({ filename: config.get('Server.logFile') }), 17 | new winston.transports.Console() 18 | ] 19 | }) 20 | 21 | module.exports = logger 22 | -------------------------------------------------------------------------------- /server/routes/auth.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const passport = require('passport') 3 | const db = require('../db') 4 | const router = express.Router() 5 | const logger = require('../logger') 6 | 7 | router.post('/login/password', passport.authenticate('local'), (req, res, next) => { 8 | return res.send('Authenticated and logged in') 9 | }) 10 | 11 | router.get('/auth', (req, res) => { 12 | if (req.user) { 13 | res.sendStatus(200) 14 | } else { 15 | res.sendStatus(401) 16 | } 17 | }) 18 | 19 | router.get('/admin', (req, res) => { 20 | if (!req.user) { 21 | return res.sendStatus(401) 22 | } 23 | 24 | db.get('SELECT is_admin FROM users WHERE id = ?', [req.user.id], (err, row) => { 25 | if (err) { 26 | logger.error(err) 27 | return res.sendStatus(500) 28 | } 29 | 30 | if (row.is_admin === 0) { 31 | res.sendStatus(401) 32 | } else { 33 | res.sendStatus(200) 34 | } 35 | }) 36 | }) 37 | 38 | router.get('/logout', (req, res) => { 39 | req.logout((err) => { 40 | if (err) { 41 | logger.error(err) 42 | res.sendStatus(500) 43 | } else { 44 | res.sendStatus(200) 45 | } 46 | }) 47 | }) 48 | 49 | router.get('/setup', (req, res) => { 50 | db.get('SELECT COUNT(*) as count FROM users', (err, row) => { 51 | if (err) { 52 | logger.error(err) 53 | return res.sendStatus(500) 54 | } 55 | 56 | if (row.count === 0) { 57 | return res.json({ setup: true }) 58 | } else { 59 | return res.json({ setup: false }) 60 | } 61 | }) 62 | }) 63 | 64 | module.exports = router 65 | -------------------------------------------------------------------------------- /server/routes/profiles.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const db = require('../db') 3 | const router = express.Router() 4 | const logger = require('../logger') 5 | 6 | router.post('/profiles', (req, res) => { 7 | if (!req.user) { 8 | return res.sendStatus(401) 9 | } 10 | 11 | let profileID = 0 12 | 13 | db.serialize(() => { 14 | db.run(`INSERT INTO profiles ( 15 | name, 16 | user, 17 | timer_enabled, 18 | duration, 19 | volume, 20 | noise_color, 21 | filter_enabled, 22 | filter_type, 23 | filter_cutoff, 24 | lfo_filter_cutoff_enabled, 25 | lfo_filter_cutoff_frequency, 26 | lfo_filter_cutoff_low, 27 | lfo_filter_cutoff_high, 28 | tremolo_enabled, 29 | tremolo_frequency, 30 | tremolo_depth) 31 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [ 32 | req.body.name, 33 | req.user.id, 34 | req.body.isTimerEnabled ? 1 : 0, 35 | req.body.duration, 36 | req.body.volume, 37 | req.body.noiseColor, 38 | req.body.isFilterEnabled ? 1 : 0, 39 | req.body.filterType, 40 | req.body.filterCutoff, 41 | req.body.isLFOFilterCutoffEnabled ? 1 : 0, 42 | req.body.lfoFilterCutoffFrequency, 43 | req.body.lfoFilterCutoffLow, 44 | req.body.lfoFilterCutoffHigh, 45 | req.body.isTremoloEnabled ? 1 : 0, 46 | req.body.tremoloFrequency, 47 | req.body.tremoloDepth 48 | ], 49 | function (err) { 50 | if (err) { 51 | logger.error(err) 52 | if (err.code === 'SQLITE_CONSTRAINT_UNIQUE') { 53 | return res.sendStatus(409) 54 | } else { 55 | return res.sendStatus(500) 56 | } 57 | } 58 | 59 | profileID = this.lastID 60 | 61 | req.body.samples.forEach(s => { 62 | db.run(`INSERT INTO profiles_samples( 63 | profile, 64 | sample, 65 | volume, 66 | reverb_enabled, 67 | reverb_pre_delay, 68 | reverb_decay, 69 | reverb_wet, 70 | playback_mode, 71 | sporadic_min, 72 | sporadic_max) 73 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [ 74 | profileID, 75 | s.id, 76 | s.volume, 77 | s.reverbEnabled, 78 | s.reverbPreDelay, 79 | s.reverbDecay, 80 | s.reverbWet, 81 | s.playbackMode, 82 | s.sporadicMin, 83 | s.sporadicMax 84 | ], 85 | (err) => { 86 | if (err) { 87 | logger.error(err) 88 | return res.sendStatus(500) 89 | } 90 | }) 91 | }) 92 | 93 | return res.json({ id: profileID }) 94 | }) 95 | }) 96 | }) 97 | 98 | router.post('/profiles/import', (req, res) => { 99 | if (!req.user) { 100 | return res.sendStatus(401) 101 | } 102 | 103 | let profileID = 0 104 | 105 | db.serialize(() => { 106 | db.run(`INSERT INTO profiles ( 107 | name, 108 | user, 109 | timer_enabled, 110 | duration, 111 | volume, 112 | noise_color, 113 | filter_enabled, 114 | filter_type, 115 | filter_cutoff, 116 | lfo_filter_cutoff_enabled, 117 | lfo_filter_cutoff_frequency, 118 | lfo_filter_cutoff_low, 119 | lfo_filter_cutoff_high, 120 | tremolo_enabled, 121 | tremolo_frequency, 122 | tremolo_depth) 123 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [ 124 | req.body.name, 125 | req.user.id, 126 | req.body.isTimerEnabled ? 1 : 0, 127 | req.body.duration, 128 | req.body.volume, 129 | req.body.noiseColor, 130 | req.body.isFilterEnabled ? 1 : 0, 131 | req.body.filterType, 132 | req.body.filterCutoff, 133 | req.body.isLFOFilterCutoffEnabled ? 1 : 0, 134 | req.body.lfoFilterCutoffFrequency, 135 | req.body.lfoFilterCutoffLow, 136 | req.body.lfoFilterCutoffHigh, 137 | req.body.isTremoloEnabled ? 1 : 0, 138 | req.body.tremoloFrequency, 139 | req.body.tremoloDepth 140 | ], 141 | function (err) { 142 | if (err) { 143 | logger.error(err) 144 | if (err.code === 'SQLITE_CONSTRAINT_UNIQUE') { 145 | return res.sendStatus(409) 146 | } else { 147 | return res.sendStatus(500) 148 | } 149 | } 150 | 151 | profileID = this.lastID 152 | 153 | return res.json({ id: profileID }) 154 | }) 155 | }) 156 | }) 157 | 158 | router.put('/profiles/:profileId', (req, res) => { 159 | if (!req.user) { 160 | return res.sendStatus(401) 161 | } 162 | 163 | db.serialize(() => { 164 | db.get('SELECT user FROM profiles WHERE id = ?', [req.params.profileId], (err, row) => { 165 | if (err) { 166 | logger.error(err) 167 | return res.sendStatus(500) 168 | } 169 | 170 | if (row.user.toString() !== req.user.id) { 171 | return res.sendStatus(401) 172 | } 173 | }) 174 | 175 | db.run(`UPDATE profiles SET 176 | timer_enabled = ?, 177 | duration = ?, 178 | volume = ?, 179 | noise_color = ?, 180 | filter_enabled = ?, 181 | filter_type = ?, 182 | filter_cutoff = ?, 183 | lfo_filter_cutoff_enabled = ?, 184 | lfo_filter_cutoff_frequency = ?, 185 | lfo_filter_cutoff_low = ?, 186 | lfo_filter_cutoff_high = ?, 187 | tremolo_enabled = ?, 188 | tremolo_frequency = ?, 189 | tremolo_depth = ? 190 | WHERE id = ?`, [ 191 | req.body.isTimerEnabled ? 1 : 0, 192 | req.body.duration, 193 | req.body.volume, 194 | req.body.noiseColor, 195 | req.body.isFilterEnabled ? 1 : 0, 196 | req.body.filterType, 197 | req.body.filterCutoff, 198 | req.body.isLFOFilterCutoffEnabled ? 1 : 0, 199 | req.body.lfoFilterCutoffFrequency, 200 | req.body.lfoFilterCutoffLow, 201 | req.body.lfoFilterCutoffHigh, 202 | req.body.isTremoloEnabled ? 1 : 0, 203 | req.body.tremoloFrequency, 204 | req.body.tremoloDepth, 205 | req.params.profileId 206 | ], 207 | (err) => { 208 | if (err) { 209 | logger.error(err) 210 | return res.sendStatus(500) 211 | } 212 | 213 | db.serialize(() => { 214 | db.run('DELETE FROM profiles_samples WHERE profile = ?', [ 215 | req.params.profileId 216 | ], 217 | (err) => { 218 | if (err) { 219 | logger.error(err) 220 | return res.sendStatus(500) 221 | } 222 | }) 223 | 224 | req.body.samples.forEach(s => { 225 | db.run(`INSERT INTO profiles_samples( 226 | profile, 227 | sample, 228 | volume, 229 | reverb_enabled, 230 | reverb_pre_delay, 231 | reverb_decay, 232 | reverb_wet, 233 | playback_mode, 234 | sporadic_min, 235 | sporadic_max) 236 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [ 237 | req.params.profileId, 238 | s.id, 239 | s.volume, 240 | s.reverbEnabled, 241 | s.reverbPreDelay, 242 | s.reverbDecay, 243 | s.reverbWet, 244 | s.playbackMode, 245 | s.sporadicMin, 246 | s.sporadicMax 247 | ], 248 | (err) => { 249 | if (err) { 250 | logger.error(err) 251 | return res.sendStatus(500) 252 | } 253 | }) 254 | }) 255 | }) 256 | return res.sendStatus(200) 257 | }) 258 | }) 259 | }) 260 | 261 | router.post('/profiles/default', (req, res) => { 262 | if (!req.user) { 263 | return res.sendStatus(401) 264 | } 265 | 266 | db.serialize(() => { 267 | db.run(`INSERT INTO profiles ( 268 | name, 269 | user, 270 | timer_enabled, 271 | duration, 272 | volume, 273 | noise_color, 274 | filter_enabled, 275 | filter_type, 276 | filter_cutoff, 277 | lfo_filter_cutoff_enabled, 278 | lfo_filter_cutoff_frequency, 279 | lfo_filter_cutoff_low, 280 | lfo_filter_cutoff_high, 281 | tremolo_enabled, 282 | tremolo_frequency, 283 | tremolo_depth) 284 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [ 285 | 'Default', req.user.id, 0, 30, -10, 'pink', 0, 'lowpass', 1000, 286 | 0, 0.5, 100, 5000, 0, 0.5, 0.5 287 | ], 288 | function (err) { 289 | if (err) { 290 | logger.error(err) 291 | return res.sendStatus(500) 292 | } else { 293 | return res.json({ id: this.lastID }) 294 | } 295 | }) 296 | }) 297 | }) 298 | 299 | router.get('/profiles', (req, res) => { 300 | if (!req.user) { 301 | return res.sendStatus(401) 302 | } 303 | 304 | db.all('SELECT id, name FROM profiles WHERE user = ?', [req.user.id], (err, rows) => { 305 | if (err) { 306 | logger.error(err) 307 | return res.sendStatus(500) 308 | } 309 | 310 | const profiles = [] 311 | 312 | rows.forEach(row => { 313 | const profile = {} 314 | 315 | profile.id = row.id 316 | profile.text = row.name 317 | 318 | profiles.push(profile) 319 | }) 320 | 321 | res.json({ profiles: profiles }) 322 | }) 323 | }) 324 | 325 | router.get('/profiles/:profileId', (req, res) => { 326 | if (!req.user) { 327 | return res.sendStatus(401) 328 | } 329 | 330 | db.serialize(() => { 331 | db.get(`SELECT 332 | name, 333 | user, 334 | timer_enabled as isTimerEnabled, 335 | duration, 336 | volume, 337 | noise_color as noiseColor, 338 | filter_enabled as isFilterEnabled, 339 | filter_type as filterType, 340 | filter_cutoff as filterCutoff, 341 | lfo_filter_cutoff_enabled as isLFOFilterCutoffEnabled, 342 | lfo_filter_cutoff_frequency as lfoFilterCutoffFrequency, 343 | lfo_filter_cutoff_low as lfoFilterCutoffLow, 344 | lfo_filter_cutoff_high as lfoFilterCutoffHigh, 345 | tremolo_enabled as isTremoloEnabled, 346 | tremolo_frequency as tremoloFrequency, 347 | tremolo_depth as tremoloDepth 348 | FROM profiles WHERE id = ?`, [req.params.profileId], (err, row) => { 349 | if (err) { 350 | logger.error(err) 351 | return res.sendStatus(500) 352 | } 353 | 354 | if (row.user.toString() !== req.user.id) { 355 | return res.sendStatus(401) 356 | } 357 | 358 | const profile = {} 359 | 360 | profile.name = row.name 361 | profile.isTimerEnabled = row.isTimerEnabled === 1 362 | profile.duration = row.duration 363 | profile.volume = row.volume 364 | profile.noiseColor = row.noiseColor 365 | profile.isFilterEnabled = row.isFilterEnabled === 1 366 | profile.filterType = row.filterType 367 | profile.filterCutoff = row.filterCutoff 368 | profile.isLFOFilterCutoffEnabled = row.isLFOFilterCutoffEnabled === 1 369 | profile.lfoFilterCutoffFrequency = row.lfoFilterCutoffFrequency 370 | profile.lfoFilterCutoffLow = row.lfoFilterCutoffLow 371 | profile.lfoFilterCutoffHigh = row.lfoFilterCutoffHigh 372 | profile.isTremoloEnabled = row.isTremoloEnabled === 1 373 | profile.tremoloFrequency = row.tremoloFrequency 374 | profile.tremoloDepth = row.tremoloDepth 375 | 376 | db.all('SELECT sample FROM profiles_samples WHERE profile = ?', [req.params.profileId], (err, rows) => { 377 | if (err) { 378 | logger.error(err) 379 | return res.sendStatus(500) 380 | } 381 | 382 | const sampleQueryArgs = [] 383 | 384 | sampleQueryArgs.push(req.params.profileId) 385 | 386 | rows.forEach(row => { 387 | sampleQueryArgs.push(row.sample) 388 | }) 389 | 390 | db.all(`SELECT 391 | samples.id, 392 | name, 393 | profiles_samples.volume, 394 | profiles_samples.reverb_enabled as reverbEnabled, 395 | profiles_samples.reverb_pre_delay as reverbPreDelay, 396 | profiles_samples.reverb_decay as reverbDecay, 397 | profiles_samples.reverb_wet as reverbWet, 398 | profiles_samples.playback_mode as playbackMode, 399 | profiles_samples.sporadic_min as sporadicMin, 400 | profiles_samples.sporadic_max as sporadicMax, 401 | fade_in as fadeIn, 402 | loop_points_enabled as loopPointsEnabled, 403 | loop_start as loopStart, 404 | loop_end as loopEnd 405 | FROM samples 406 | INNER JOIN profiles_samples 407 | ON profiles_samples.sample = samples.id 408 | AND profiles_samples.profile = ? 409 | WHERE samples.id IN ( ` + 410 | sampleQueryArgs.map(() => { return '?' }).join(',') + ' )', sampleQueryArgs, (err, rows) => { 411 | if (err) { 412 | logger.error(err) 413 | return res.sendStatus(500) 414 | } 415 | 416 | const samples = [] 417 | 418 | rows.forEach(row => { 419 | const sample = {} 420 | 421 | sample.id = row.id 422 | sample.name = row.name 423 | sample.volume = row.volume 424 | sample.fadeIn = row.fadeIn 425 | sample.loopPointsEnabled = row.loopPointsEnabled === 1 426 | sample.loopStart = row.loopStart 427 | sample.loopEnd = row.loopEnd 428 | sample.reverbEnabled = row.reverbEnabled === 1 429 | sample.reverbPreDelay = row.reverbPreDelay 430 | sample.reverbDecay = row.reverbDecay 431 | sample.reverbWet = row.reverbWet 432 | sample.playbackMode = row.playbackMode 433 | sample.sporadicMin = row.sporadicMin 434 | sample.sporadicMax = row.sporadicMax 435 | 436 | samples.push(sample) 437 | }) 438 | 439 | profile.samples = samples 440 | 441 | res.json({ profile: profile }) 442 | }) 443 | }) 444 | }) 445 | }) 446 | }) 447 | 448 | router.delete('/profiles/:profileId', (req, res) => { 449 | if (!req.user) { 450 | return res.sendStatus(401) 451 | } 452 | 453 | db.serialize(() => { 454 | db.get('SELECT user FROM profiles WHERE id = ?', [req.params.profileId], (err, row) => { 455 | if (err) { 456 | logger.error(err) 457 | return res.sendStatus(500) 458 | } 459 | 460 | if (row.user.toString() !== req.user.id) { 461 | return res.sendStatus(401) 462 | } 463 | }) 464 | 465 | db.run('DELETE FROM profiles WHERE id = ?', [req.params.profileId], (err) => { 466 | if (err) { 467 | logger.error(err) 468 | return res.sendStatus(500) 469 | } 470 | }) 471 | 472 | db.run('DELETE FROM profiles_samples WHERE profile = ?', [req.params.profileId], (err) => { 473 | if (err) { 474 | logger.error(err) 475 | return res.sendStatus(500) 476 | } else { 477 | return res.sendStatus(200) 478 | } 479 | }) 480 | }) 481 | }) 482 | 483 | module.exports = router 484 | -------------------------------------------------------------------------------- /server/routes/samples.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const config = require('config') 3 | const multer = require('multer') 4 | const fs = require('fs') 5 | const path = require('path') 6 | const storage = multer.diskStorage({ 7 | destination: config.get('Server.sampleUploadPath'), 8 | filename: (req, file, cb) => { 9 | if (!req.user) { 10 | const err = new Error('Unauthenticated user attempted to upload sample') 11 | logger.error(err) 12 | cb(err, null) 13 | } else { 14 | cb(null, req.user.id + '_' + req.body.name) 15 | } 16 | } 17 | }) 18 | const upload = multer({ 19 | storage: storage, 20 | limits: { fileSize: config.get('Server.maxSampleSize') } 21 | }) 22 | const db = require('../db') 23 | const router = express.Router() 24 | const logger = require('../logger') 25 | 26 | router.post('/samples', upload.single('sample'), (req, res, next) => { 27 | if (!req.user) { 28 | return res.sendStatus(401) 29 | } 30 | 31 | db.serialize(() => { 32 | db.get('SELECT can_upload FROM users WHERE id = ?', [req.user.id], (err, row) => { 33 | if (err) { 34 | logger.error(err) 35 | deleteSample(req.user.id + '_' + req.body.name) 36 | return res.sendStatus(500) 37 | } 38 | 39 | if (row.can_upload === 0) { 40 | deleteSample(req.user.id + '_' + req.body.name) 41 | return res.sendStatus(401) 42 | } 43 | 44 | db.run('INSERT INTO samples (name, user) VALUES (?, ?)', [ 45 | req.body.name, 46 | req.user.id 47 | ], 48 | (err) => { 49 | if (err) { 50 | logger.error(err) 51 | deleteSample(req.user.id + '_' + req.body.name) 52 | if (err.code === 'SQLITE_CONSTRAINT_UNIQUE') { 53 | return res.sendStatus(409) 54 | } else { 55 | return res.sendStatus(500) 56 | } 57 | } else { 58 | return res.sendStatus(200) 59 | } 60 | }) 61 | }) 62 | }) 63 | }) 64 | 65 | function deleteSample (fileName) { 66 | fs.unlink(path.join(__dirname, '../../', config.get('Server.sampleUploadPath'), fileName), (err) => { 67 | if (err) { 68 | logger.error(err) 69 | } 70 | }) 71 | } 72 | 73 | router.get('/samples', (req, res) => { 74 | if (!req.user) { 75 | return res.sendStatus(401) 76 | } 77 | 78 | const samples = [] 79 | 80 | db.all(`SELECT 81 | id, 82 | name, 83 | fade_in as fadeIn, 84 | loop_points_enabled as loopPointsEnabled, 85 | loop_start as loopStart, 86 | loop_end as loopEnd 87 | FROM samples WHERE user = ?`, [req.user.id], (err, rows) => { 88 | if (err) { 89 | logger.error(err) 90 | return res.sendStatus(500) 91 | } 92 | 93 | rows.forEach(row => { 94 | const sample = {} 95 | 96 | sample.id = row.id 97 | sample.name = row.name 98 | sample.fadeIn = row.fadeIn 99 | sample.loopPointsEnabled = row.loopPointsEnabled === 1 100 | sample.loopStart = row.loopStart 101 | sample.loopEnd = row.loopEnd 102 | sample.user = req.user.id 103 | 104 | samples.push(sample) 105 | }) 106 | 107 | res.json({ samples: samples }) 108 | }) 109 | }) 110 | 111 | router.get('/samples/:sampleId', (req, res) => { 112 | if (!req.user) { 113 | return res.sendStatus(401) 114 | } 115 | 116 | db.get(`SELECT 117 | id, 118 | name, 119 | fade_in as fadeIn, 120 | loop_points_enabled as loopPointsEnabled, 121 | loop_start as loopStart, 122 | loop_end as loopEnd 123 | FROM samples WHERE user = ? AND id = ?`, [req.user.id, req.params.sampleId], (err, row) => { 124 | if (err) { 125 | logger.error(err) 126 | return res.sendStatus(500) 127 | } 128 | 129 | const sample = {} 130 | 131 | sample.id = row.id 132 | sample.name = row.name 133 | sample.fadeIn = row.fadeIn 134 | sample.loopPointsEnabled = row.loopPointsEnabled === 1 135 | sample.loopStart = row.loopStart 136 | sample.loopEnd = row.loopEnd 137 | sample.user = req.user.id 138 | 139 | res.json({ sample: sample }) 140 | }) 141 | }) 142 | 143 | router.put('/samples/:sampleId', (req, res) => { 144 | if (!req.user) { 145 | return res.sendStatus(401) 146 | } 147 | 148 | db.serialize(() => { 149 | db.get('SELECT user FROM samples WHERE id = ?', [req.params.sampleId], (err, row) => { 150 | if (err) { 151 | logger.error(err) 152 | return res.sendStatus(500) 153 | } 154 | 155 | if (row.user.toString() !== req.user.id) { 156 | return res.sendStatus(401) 157 | } 158 | }) 159 | 160 | db.run(`UPDATE samples SET 161 | fade_in = ?, 162 | loop_points_enabled = ?, 163 | loop_start = ?, 164 | loop_end = ? 165 | WHERE id = ?`, [ 166 | req.body.fadeIn, 167 | req.body.loopPointsEnabled ? 1 : 0, 168 | req.body.loopStart, 169 | req.body.loopEnd, 170 | req.params.sampleId 171 | ], 172 | (err) => { 173 | if (err) { 174 | logger.error(err) 175 | return res.sendStatus(500) 176 | } 177 | 178 | return res.sendStatus(200) 179 | }) 180 | }) 181 | }) 182 | 183 | module.exports = router 184 | -------------------------------------------------------------------------------- /server/routes/users.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const crypto = require('crypto') 3 | const db = require('../db') 4 | const router = express.Router() 5 | const logger = require('../logger') 6 | 7 | router.get('/users/current', (req, res) => { 8 | if (!req.user) { 9 | return res.sendStatus(401) 10 | } 11 | 12 | db.get(`SELECT 13 | is_admin as isAdmin, 14 | dark_mode as darkMode, 15 | can_upload as canUpload, 16 | * FROM users WHERE id = ?`, [req.user.id], (err, row) => { 17 | if (err) { 18 | logger.error(err) 19 | return res.sendStatus(500) 20 | } 21 | 22 | const user = {} 23 | 24 | if (row) { 25 | user.id = row.id 26 | user.username = row.username 27 | user.name = row.name 28 | user.isAdmin = row.isAdmin === 1 29 | user.darkMode = row.darkMode === 1 30 | user.canUpload = row.canUpload === 1 31 | user.preferences = JSON.parse(row.preferences) 32 | } 33 | 34 | res.json({ user: user }) 35 | }) 36 | }) 37 | 38 | router.get('/users', (req, res) => { 39 | if (!req.user) { 40 | return res.sendStatus(401) 41 | } 42 | 43 | const users = [] 44 | 45 | db.all('SELECT id, username, name, is_admin as isAdmin, can_upload as canUpload FROM users', (err, rows) => { 46 | if (err) { 47 | logger.error(err) 48 | return res.sendStatus(500) 49 | } 50 | 51 | rows.forEach(row => { 52 | const user = {} 53 | 54 | user.id = row.id 55 | user.username = row.username 56 | user.name = row.name 57 | user.isAdmin = row.isAdmin === 1 58 | user.canUpload = row.canUpload === 1 59 | 60 | users.push(user) 61 | }) 62 | 63 | res.json({ users: users }) 64 | }) 65 | }) 66 | 67 | router.post('/users', (req, res) => { 68 | db.serialize(() => { 69 | db.get('SELECT COUNT(*) as count FROM users', (err, row) => { 70 | if (err) { 71 | logger.error(err) 72 | return res.sendStatus(500) 73 | } 74 | 75 | const defaultPreferences = '{"accentColor":{"alpha":1,"hex":"#607D8B","hexa":"#607D8BFF","hsla":{"h":200,"s":18,"l":46,"a":1},"hsva":{"h":200,"s":31,"v":55,"a":1},"hue":200,"rgba":{"r":96,"g":125,"b":139,"a":1}}}' 76 | 77 | if (row.count !== 0) { 78 | if (!req.user) { 79 | return res.sendStatus(401) 80 | } 81 | 82 | db.get('SELECT is_admin as isAdmin FROM users WHERE id = ?', [req.user.id], (err, row) => { 83 | if (err) { 84 | logger.error(err) 85 | return res.sendStatus(500) 86 | } 87 | 88 | if (row.isAdmin !== 1) { 89 | return res.sendStatus(401) 90 | } 91 | 92 | const salt = crypto.randomBytes(16) 93 | crypto.pbkdf2(req.body.password, salt, 10000, 32, 'sha256', (err, hashedPassword) => { 94 | if (err) { 95 | logger.error(err) 96 | return res.sendStatus(500) 97 | } 98 | 99 | db.run(`INSERT INTO users (username, hashed_password, salt, name, is_admin, dark_mode, can_upload, preferences) 100 | VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [ 101 | req.body.username, 102 | hashedPassword, 103 | salt, 104 | req.body.name, 105 | req.body.isAdmin, 106 | req.body.darkMode, 107 | req.body.canUpload, 108 | defaultPreferences 109 | ], (err) => { 110 | if (err) { 111 | logger.error(err) 112 | if (err.code === 'SQLITE_CONSTRAINT_UNIQUE') { 113 | return res.sendStatus(409) 114 | } else { 115 | return res.sendStatus(500) 116 | } 117 | } 118 | 119 | return res.sendStatus(200) 120 | }) 121 | }) 122 | }) 123 | } else { 124 | const salt = crypto.randomBytes(16) 125 | crypto.pbkdf2(req.body.password, salt, 10000, 32, 'sha256', (err, hashedPassword) => { 126 | if (err) { 127 | logger.error(err) 128 | return res.sendStatus(500) 129 | } 130 | 131 | db.run(`INSERT INTO users (username, hashed_password, salt, name, is_admin, dark_mode, can_upload, preferences) 132 | VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [ 133 | req.body.username, 134 | hashedPassword, 135 | salt, 136 | req.body.name, 137 | req.body.isAdmin, 138 | req.body.darkMode, 139 | req.body.canUpload, 140 | defaultPreferences 141 | ], function (err) { 142 | if (err) { 143 | logger.error(err) 144 | if (err.code === 'SQLITE_CONSTRAINT_UNIQUE') { 145 | return res.sendStatus(409) 146 | } else { 147 | return res.sendStatus(500) 148 | } 149 | } 150 | 151 | const user = { 152 | id: this.lastID.toString(), 153 | username: req.body.username, 154 | displayName: req.body.name 155 | } 156 | req.login(user, (err) => { 157 | if (err) { 158 | logger.error(err) 159 | return res.sendStatus(500) 160 | } else { 161 | return res.sendStatus(200) 162 | } 163 | }) 164 | }) 165 | }) 166 | } 167 | }) 168 | }) 169 | }) 170 | 171 | router.patch('/users/admin/:userId', (req, res) => { 172 | if (!req.user) { 173 | return res.sendStatus(401) 174 | } 175 | 176 | db.serialize(() => { 177 | db.get('SELECT is_admin FROM users WHERE id = ?', [req.user.id], (err, row) => { 178 | if (err) { 179 | logger.error(err) 180 | return res.sendStatus(500) 181 | } 182 | 183 | if (row.is_admin === 0) { 184 | return res.sendStatus(401) 185 | } 186 | }) 187 | 188 | db.run('UPDATE users SET is_admin = ? WHERE id = ?', [req.body.isAdmin ? 1 : 0, req.params.userId], (err) => { 189 | if (err) { 190 | logger.error(err) 191 | return res.sendStatus(500) 192 | } else { 193 | return res.sendStatus(200) 194 | } 195 | }) 196 | }) 197 | }) 198 | 199 | router.patch('/users/upload/:userId', (req, res) => { 200 | if (!req.user) { 201 | return res.sendStatus(401) 202 | } 203 | 204 | db.serialize(() => { 205 | db.get('SELECT is_admin FROM users WHERE id = ?', [req.user.id], (err, row) => { 206 | if (err) { 207 | logger.error(err) 208 | return res.sendStatus(500) 209 | } 210 | 211 | if (row.is_admin === 0) { 212 | return res.sendStatus(401) 213 | } 214 | }) 215 | 216 | db.run('UPDATE users SET can_upload = ? WHERE id = ?', [req.body.canUpload ? 1 : 0, req.params.userId], (err) => { 217 | if (err) { 218 | logger.error(err) 219 | return res.sendStatus(500) 220 | } else { 221 | return res.sendStatus(200) 222 | } 223 | }) 224 | }) 225 | }) 226 | 227 | router.patch('/users/dark-mode', (req, res) => { 228 | if (!req.user) { 229 | return res.sendStatus(401) 230 | } 231 | 232 | db.serialize(() => { 233 | db.run('UPDATE users SET dark_mode = ? WHERE id = ?', [req.body.darkMode ? 1 : 0, req.user.id], (err) => { 234 | if (err) { 235 | logger.error(err) 236 | return res.sendStatus(500) 237 | } else { 238 | return res.sendStatus(200) 239 | } 240 | }) 241 | }) 242 | }) 243 | 244 | router.patch('/users/password', (req, res) => { 245 | if (!req.user) { 246 | return res.sendStatus(401) 247 | } 248 | 249 | const salt = crypto.randomBytes(16) 250 | crypto.pbkdf2(req.body.password, salt, 10000, 32, 'sha256', (err, hashedPassword) => { 251 | if (err) { 252 | logger.error(err) 253 | return res.sendStatus(500) 254 | } 255 | 256 | db.run('UPDATE users SET hashed_password = ?, salt = ? WHERE id = ?', [ 257 | hashedPassword, 258 | salt, 259 | req.user.id 260 | ], (err) => { 261 | if (err) { 262 | logger.error(err) 263 | return res.sendStatus(500) 264 | } 265 | 266 | return res.sendStatus(200) 267 | }) 268 | }) 269 | }) 270 | 271 | router.delete('/users/:userId', (req, res) => { 272 | if (!req.user) { 273 | return res.sendStatus(401) 274 | } 275 | 276 | db.serialize(() => { 277 | db.get('SELECT is_admin FROM users WHERE id = ?', [req.user.id], (err, row) => { 278 | if (err) { 279 | logger.error(err) 280 | return res.sendStatus(500) 281 | } 282 | 283 | if (row.is_admin === 0) { 284 | return res.sendStatus(401) 285 | } 286 | }) 287 | 288 | db.run('DELETE FROM users WHERE id = ?', [req.params.userId], (err) => { 289 | if (err) { 290 | logger.error(err) 291 | return res.sendStatus(500) 292 | } else { 293 | return res.sendStatus(200) 294 | } 295 | }) 296 | }) 297 | }) 298 | 299 | router.patch('/users/preferences', (req, res) => { 300 | if (!req.user) { 301 | return res.sendStatus(401) 302 | } 303 | 304 | const preferences = JSON.stringify(req.body.preferences) 305 | 306 | db.serialize(() => { 307 | db.run('UPDATE users SET preferences = ? WHERE id = ?', [preferences, req.user.id], (err) => { 308 | if (err) { 309 | logger.error(err) 310 | return res.sendStatus(500) 311 | } else { 312 | return res.sendStatus(200) 313 | } 314 | }) 315 | }) 316 | }) 317 | 318 | module.exports = router 319 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 25 | -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaythomas0/noisedash/99857c7a0d379df2128fbd281bee684c7c2d2ce2/src/assets/logo.png -------------------------------------------------------------------------------- /src/assets/logo.svg: -------------------------------------------------------------------------------- 1 | Artboard 46 2 | -------------------------------------------------------------------------------- /src/axios.js: -------------------------------------------------------------------------------- 1 | import Axios from 'axios' 2 | 3 | const instance = Axios.create({ 4 | withCredentials: true 5 | }) 6 | 7 | export default instance 8 | -------------------------------------------------------------------------------- /src/components/AccountPage.vue: -------------------------------------------------------------------------------- 1 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /src/components/AdminPage.vue: -------------------------------------------------------------------------------- 1 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /src/components/AppBar.vue: -------------------------------------------------------------------------------- 1 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /src/components/LoginPage.vue: -------------------------------------------------------------------------------- 1 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/components/NoisePage.vue: -------------------------------------------------------------------------------- 1 | 1105 | 1106 | 1107 | -------------------------------------------------------------------------------- /src/components/RegisterPage.vue: -------------------------------------------------------------------------------- 1 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /src/components/account.js: -------------------------------------------------------------------------------- 1 | export default { 2 | name: 'Account', 3 | 4 | data: () => ({ 5 | currentUser: {}, 6 | changePasswordDialog: false, 7 | isPasswordValid: false, 8 | password: '', 9 | accentColor: {}, 10 | snackbar: false, 11 | snackbarText: '', 12 | rules: { 13 | required: v => !!v || 'Required' 14 | } 15 | }), 16 | created () { 17 | this.getCurrentUser() 18 | }, 19 | methods: { 20 | getCurrentUser () { 21 | this.$http.get('/users/current') 22 | .then(response => { 23 | if (response.status === 200) { 24 | this.currentUser = response.data.user 25 | this.accentColor = this.currentUser.preferences.accentColor 26 | } 27 | }) 28 | }, 29 | updatePassword () { 30 | this.$http.patch('/users/password', { 31 | password: this.password 32 | }) 33 | .then(response => { 34 | if (response.status === 200) { 35 | this.changePasswordDialog = false 36 | this.snackbarText = 'Password Changed' 37 | this.snackbar = true 38 | } 39 | }) 40 | }, 41 | resetChangePasswordForm () { 42 | if (this.$refs.changePasswordForm) { 43 | this.$refs.changePasswordForm.reset() 44 | } 45 | }, 46 | toggleDarkMode () { 47 | this.$http.patch('/users/dark-mode', { 48 | darkMode: this.$vuetify.theme.dark 49 | }) 50 | }, 51 | updateAccentColor () { 52 | const preferences = { accentColor: this.accentColor } 53 | this.$http.patch('/users/preferences', { 54 | preferences: preferences 55 | }) 56 | this.$vuetify.theme.themes.dark.primary = this.accentColor.hex 57 | this.$vuetify.theme.themes.light.primary = this.accentColor.hex 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/components/admin.js: -------------------------------------------------------------------------------- 1 | export default { 2 | name: 'Admin', 3 | 4 | data: () => ({ 5 | currentUser: {}, 6 | users: [], 7 | snackbar: false, 8 | snackbarText: '', 9 | registerUserDialog: false, 10 | isUserValid: false, 11 | name: '', 12 | username: '', 13 | password: '', 14 | isAdmin: false, 15 | canUpload: false, 16 | rules: { 17 | required: v => !!v || 'Required' 18 | } 19 | }), 20 | created () { 21 | this.getCurrentUser() 22 | this.getUsers() 23 | }, 24 | methods: { 25 | getUsers () { 26 | this.$http.get('/users') 27 | .then(response => { 28 | if (response.status === 200) { 29 | this.users = response.data.users 30 | } 31 | }) 32 | }, 33 | getCurrentUser () { 34 | this.$http.get('/users/current') 35 | .then(response => { 36 | if (response.status === 200) { 37 | this.currentUser = response.data.user 38 | } 39 | }) 40 | }, 41 | updateUserAdmin (id, isAdmin) { 42 | this.$http.patch('/users/admin/'.concat(id), { 43 | isAdmin: isAdmin 44 | }) 45 | .then(response => { 46 | if (response.status === 200) { 47 | this.snackbarText = 'User updated' 48 | } 49 | }) 50 | .catch(() => { 51 | this.snackbarText = 'Error updating user' 52 | }) 53 | }, 54 | updateUserUpload (id, canUpload) { 55 | this.$http.patch('/users/upload/'.concat(id), { 56 | canUpload: canUpload 57 | }) 58 | .then(response => { 59 | if (response.status === 200) { 60 | this.snackbarText = 'User updated' 61 | } 62 | }) 63 | .catch(() => { 64 | this.snackbarText = 'Error updating user' 65 | }) 66 | }, 67 | deleteUser (id) { 68 | this.$http.delete('/users/'.concat(id)) 69 | .then(response => { 70 | if (response.status === 200) { 71 | this.getUsers() 72 | } 73 | }) 74 | }, 75 | registerUser () { 76 | this.$http.post('/users', { 77 | name: this.name, 78 | username: this.username, 79 | password: this.password, 80 | isAdmin: this.isAdmin, 81 | darkMode: 0, 82 | canUpload: this.canUpload 83 | }) 84 | .then(response => { 85 | if (response.status === 200) { 86 | this.registerUserDialog = false 87 | this.snackbarText = 'User Registered' 88 | this.snackbar = true 89 | this.getUsers() 90 | } 91 | }) 92 | }, 93 | resetRegisterUserForm () { 94 | if (this.$refs.registerUserForm) { 95 | this.$refs.registerUserForm.reset() 96 | } 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/components/appbar.js: -------------------------------------------------------------------------------- 1 | export default { 2 | name: 'AppBar', 3 | 4 | data: () => ({ 5 | drawyer: false, 6 | isAdmin: false, 7 | loggedIn: false 8 | }), 9 | created () { 10 | this.getUserPreferences() 11 | }, 12 | methods: { 13 | home () { 14 | this.$router.push('/') 15 | }, 16 | account () { 17 | this.$router.push('/account') 18 | }, 19 | admin () { 20 | this.$router.push('/admin') 21 | }, 22 | logout () { 23 | this.$http.get('/logout') 24 | .then(response => { 25 | if (response.status === 200) { 26 | this.$router.push('/login') 27 | } 28 | }) 29 | }, 30 | checkForAdmin () { 31 | this.loggedIn = false 32 | this.drawyer = true 33 | this.$http.get('/users/current') 34 | .then(response => { 35 | if (response.status === 200) { 36 | this.loggedIn = true 37 | this.isAdmin = response.data.user.isAdmin 38 | } 39 | }) 40 | .catch(() => { 41 | this.isAdmin = false 42 | }) 43 | }, 44 | getUserPreferences () { 45 | this.$http.get('/users/current') 46 | .then(response => { 47 | if (response.status === 200) { 48 | const preferences = response.data.user.preferences 49 | this.$vuetify.theme.themes.dark.primary = preferences.accentColor.hex 50 | this.$vuetify.theme.themes.light.primary = preferences.accentColor.hex 51 | } 52 | }) 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/components/login.js: -------------------------------------------------------------------------------- 1 | export default { 2 | name: 'Login', 3 | 4 | data: () => ({ 5 | valid: false, 6 | username: '', 7 | password: '', 8 | snackbar: false, 9 | snackbarText: '', 10 | usernameRules: [ 11 | v => !!v || 'Username is required' 12 | ], 13 | passwordRules: [ 14 | v => !!v || 'Password is required' 15 | ] 16 | }), 17 | methods: { 18 | login () { 19 | this.$http.post('/login/password', { 20 | username: this.username, 21 | password: this.password 22 | }) 23 | .then(response => { 24 | if (response.status === 200) { 25 | this.$router.push('/') 26 | } 27 | }) 28 | .catch((error) => { 29 | if (error.response.status === 401) { 30 | this.snackbarText = 'Login Failed: Unauthorized' 31 | } else { 32 | this.snackbarText = 'Login Failed' 33 | } 34 | this.snackbar = true 35 | }) 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/components/noise.js: -------------------------------------------------------------------------------- 1 | import * as Tone from 'tone' 2 | 3 | export default { 4 | name: 'Noise', 5 | 6 | data: () => ({ 7 | mainPlayLoading: true, 8 | isTimerValid: false, 9 | selectedProfile: {}, 10 | profileItems: [], 11 | profileDialog: false, 12 | profileName: '', 13 | isProfileValid: false, 14 | profileMoreDialog: false, 15 | importDialog: false, 16 | isImportValid: false, 17 | exportDialog: false, 18 | importedProfile: null, 19 | importedProfileName: '', 20 | exportedProfile: {}, 21 | infoSnackbar: false, 22 | infoSnackbarText: '', 23 | playDisabled: false, 24 | isTimerEnabled: false, 25 | hours: 0, 26 | minutes: 0, 27 | seconds: 30, 28 | duration: 30, 29 | timeRemaining: 0, 30 | noiseColor: 'pink', 31 | noiseColorItems: ['pink', 'white', 'brown'], 32 | volume: -10, 33 | isFilterEnabled: false, 34 | filterCutoff: 1000, 35 | filterType: 'lowpass', 36 | filterTypeItems: ['lowpass', 'highpass', 'bandpass', 'lowshelf', 'highshelf', 'notch', 'allpass', 'peaking'], 37 | isLFOFilterCutoffEnabled: false, 38 | lfoFilterCutoffFrequency: 0.5, 39 | lfoFilterCutoffMin: 0, 40 | lfoFilterCutoffMax: 5000, 41 | lfoFilterCutoffRange: [100, 5000], 42 | isTremoloEnabled: false, 43 | tremoloFrequency: 0.5, 44 | tremoloDepth: 0.5, 45 | isReverbEnabled: false, 46 | allSamples: [], 47 | loadedSamples: [], 48 | selectedSample: null, 49 | uploadSampleDialog: false, 50 | addSampleDialog: false, 51 | checkedSamples: [], 52 | sampleName: '', 53 | isSampleUploadValid: false, 54 | canUpload: false, 55 | editSampleDialog: false, 56 | previewSampleLoopPointsEnabled: false, 57 | previewSampleLoopStart: 0, 58 | previewSampleLoopEnd: 0, 59 | previewSampleFadeIn: 0, 60 | previewSamplePlaying: false, 61 | selectedPreviewSample: {}, 62 | previewSampleItems: [], 63 | isEditSampleValid: false, 64 | previewSampleButtonText: 'Preview Sample', 65 | previewSampleLoading: true, 66 | previewSampleLength: 0, 67 | startRecordingDialog: false, 68 | recordingDialog: false, 69 | recordingTimeElapsed: 0, 70 | recordedProfile: {}, 71 | recordingFileName: '', 72 | isRecordingValid: false, 73 | unsavedWork: false, 74 | saveProfileText: 'Save Profile', 75 | unwatch: null, 76 | confirmSwitchProfileDialog: false, 77 | activeProfile: {}, 78 | isSporadicValid: false, 79 | errorSnackbar: false, 80 | errorSnackbarText: '', 81 | rules: { 82 | lt (n) { 83 | return value => (!isNaN(parseInt(value, 10)) && value < n) || 'Must be less than ' + n 84 | }, 85 | gt (n) { 86 | return value => (!isNaN(parseInt(value, 10)) && value > n) || 'Must be greater than ' + n 87 | }, 88 | required () { 89 | return value => !!value || 'Required' 90 | } 91 | } 92 | }), 93 | computed: { 94 | unloadedSamples: function () { 95 | const samples = [] 96 | this.allSamples.forEach(s1 => { 97 | const result = this.loadedSamples.find(s2 => s2.id === s1.id) 98 | if (!result) { 99 | samples.push(s1) 100 | } 101 | }) 102 | return samples 103 | }, 104 | changeableSettings: function () { 105 | const settings = [ 106 | this.isTimerEnabled, 107 | this.hours, 108 | this.minutes, 109 | this.seconds, 110 | this.volume, 111 | this.noiseColor, 112 | this.isFilterEnabled, 113 | this.filterType, 114 | this.filterCutoff, 115 | this.isLFOFilterCutoffEnabled, 116 | this.lfoFilterCutoffFrequency, 117 | this.lfoFilterCutoffRange, 118 | this.isTremoloEnabled, 119 | this.tremoloDepth, 120 | this.tremoloFrequency, 121 | this.isTimerEnabled, 122 | this.loadedSamples 123 | ] 124 | 125 | this.loadedSamples.forEach(s => { 126 | settings.push(s.volume) 127 | settings.push(s.reverbEnabled) 128 | settings.push(s.reverbPreDelay) 129 | settings.push(s.reverbDecay) 130 | settings.push(s.reverbWet) 131 | settings.push(s.playbackMode) 132 | settings.push(s.sporadicMin) 133 | settings.push(s.sporadicMax) 134 | }) 135 | 136 | return settings 137 | } 138 | }, 139 | created () { 140 | this.noise = new Tone.Noise() 141 | this.filter = new Tone.Filter() 142 | this.tremolo = new Tone.Tremolo() 143 | this.lfo = new Tone.LFO() 144 | this.players = new Tone.Players() 145 | this.samplePreviewPlayer = new Tone.Player().toDestination() 146 | this.samplePreviewPlayer.loop = true 147 | this.recorder = new Tone.Recorder() 148 | 149 | this.populateProfileItems(0) 150 | this.populatePreviewSampleItems() 151 | this.getSamples() 152 | this.getCurrentUser() 153 | }, 154 | beforeDestroy () { 155 | this.stop() 156 | }, 157 | methods: { 158 | async play () { 159 | if (!this.players.loaded) { 160 | return 161 | } 162 | 163 | await Tone.start() 164 | 165 | this.playDisabled = true 166 | Tone.Transport.cancel() 167 | 168 | if (!this.isFilterEnabled && !this.isTremoloEnabled) { 169 | this.noise = new Tone.Noise({ volume: this.volume, type: this.noiseColor }).toDestination() 170 | } else if (!this.isFilterEnabled && this.isTremoloEnabled) { 171 | this.tremolo = new Tone.Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start() 172 | this.noise = new Tone.Noise({ volume: this.volume, type: this.noiseColor }).connect(this.tremolo) 173 | } else if (this.isFilterEnabled && !this.isTremoloEnabled) { 174 | this.filter = new Tone.Filter(this.filterCutoff, this.filterType).toDestination() 175 | this.noise = new Tone.Noise({ volume: this.volume, type: this.noiseColor }).connect(this.filter) 176 | } else if (this.isFilterEnabled && this.isTremoloEnabled) { 177 | this.tremolo = new Tone.Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start() 178 | this.filter = new Tone.Filter(this.filterCutoff, this.filterType).connect(this.tremolo) 179 | this.noise = new Tone.Noise({ volume: this.volume, type: this.noiseColor }).connect(this.filter) 180 | } else { 181 | this.tremolo = new Tone.Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start() 182 | this.filter = new Tone.Filter(this.filterCutoff, this.filterType).connect(this.tremolo) 183 | this.noise = new Tone.Noise({ volume: this.volume, type: this.noiseColor }).connect(this.filter) 184 | } 185 | 186 | if (this.isLFOFilterCutoffEnabled) { 187 | this.lfo = new Tone.LFO({ frequency: this.lfoFilterCutoffFrequency, min: this.lfoFilterCutoffRange[0], max: this.lfoFilterCutoffRange[1] }) 188 | this.lfo.connect(this.filter.frequency).start() 189 | } 190 | 191 | if (this.isTimerEnabled) { 192 | this.duration = parseInt((this.hours * 3600)) + parseInt((this.minutes * 60)) + parseInt(this.seconds) 193 | this.timeRemaining = this.duration 194 | this.transportInterval = setInterval(() => this.stop(), this.duration * 1000 + 100) 195 | this.timeRemainingInterval = setInterval(() => this.startTimer(), 1000) 196 | Tone.Transport.loopEnd = this.duration 197 | 198 | this.noise.sync().start(0).stop(this.duration) 199 | } else { 200 | this.noise.sync().start(0) 201 | } 202 | 203 | this.loadedSamples.forEach(s => { 204 | this.players.player(s.id).loop = true 205 | this.players.player(s.id).fadeIn = s.fadeIn 206 | if (s.loopPointsEnabled) { 207 | this.players.player(s.id).setLoopPoints(s.loopStart, s.loopEnd) 208 | } else { 209 | this.players.player(s.id).setLoopPoints(0, this.players.player(s.id).buffer.duration) 210 | } 211 | this.players.player(s.id).volume.value = s.volume 212 | 213 | this.players.player(s.id).disconnect() 214 | if (s.reverbEnabled) { 215 | const reverb = new Tone.Reverb(s.reverbDecay).toDestination() 216 | reverb.set({ preDelay: s.reverbPreDelay, wet: s.reverbWet }) 217 | this.players.player(s.id).connect(reverb) 218 | } else { 219 | this.players.player(s.id).toDestination() 220 | } 221 | 222 | if (s.playbackMode === 'sporadic') { 223 | this.players.player(s.id).loop = false 224 | 225 | const maxInt = parseInt(s.sporadicMax, 10) 226 | const minInt = parseInt(s.sporadicMin, 10) 227 | 228 | if (minInt <= maxInt) { 229 | const rand = Math.floor(Math.random() * (maxInt - minInt + 1) + minInt) 230 | s.initialSporadicPlayInterval = setInterval(() => this.playSporadicSample(s.id), rand * 1000) 231 | } 232 | } else { 233 | this.players.player(s.id).loop = true 234 | 235 | if (this.isTimerEnabled) { 236 | this.players.player(s.id).unsync().sync().start(0).stop(this.duration) 237 | } else { 238 | this.players.player(s.id).unsync().sync().start(0) 239 | } 240 | } 241 | }) 242 | 243 | Tone.Transport.start('+0.1') 244 | }, 245 | playSporadicSample (id) { 246 | const sample = this.loadedSamples.find(s => s.id === id) 247 | 248 | clearInterval(sample.initialSporadicPlayInterval) 249 | clearInterval(sample.sporadicInterval) 250 | 251 | this.players.player(id).unsync().sync().start() 252 | 253 | const maxInt = parseInt(sample.sporadicMax, 10) 254 | const minInt = parseInt(sample.sporadicMin, 10) 255 | sample.playNextTime = Math.floor(Math.random() * (maxInt - minInt + 1) + minInt) 256 | 257 | sample.sporadicInterval = setInterval(() => this.playSporadicSample(id), sample.playNextTime * 1000) 258 | }, 259 | stop () { 260 | clearInterval(this.transportInterval) 261 | Tone.Transport.stop() 262 | this.playDisabled = false 263 | 264 | clearInterval(this.timeRemainingInterval) 265 | this.timeRemaining = 0 266 | this.duration = 0 267 | 268 | this.loadedSamples.forEach(s => { 269 | if (s.playbackMode === 'sporadic') { 270 | clearInterval(s.initialSporadicPlayInterval) 271 | clearInterval(s.sporadicInterval) 272 | } 273 | }) 274 | }, 275 | startTimer () { 276 | this.timeRemaining -= 1 277 | }, 278 | updateVolume () { 279 | this.noise.volume.value = this.volume 280 | }, 281 | updateNoiseColor () { 282 | this.noise.type = this.noiseColor 283 | }, 284 | updateFilterType () { 285 | this.filter.type = this.filterType 286 | }, 287 | updateFilterCutoff () { 288 | this.filter.set({ frequency: this.filterCutoff }) 289 | }, 290 | updateLFOFilterCutoffFrequency () { 291 | this.lfo.set({ frequency: this.lfoFilterCutoffFrequency }) 292 | }, 293 | updateLFOFilterCutoffRange () { 294 | this.lfo.set({ min: this.lfoFilterCutoffRange[0], max: this.lfoFilterCutoffRange[1] }) 295 | }, 296 | updateTremoloFrequency () { 297 | this.tremolo.set({ frequency: this.tremoloFrequency }) 298 | }, 299 | updateTremoloDepth () { 300 | this.tremolo.set({ depth: this.tremoloDepth }) 301 | }, 302 | updateAudioChain () { 303 | this.noise.disconnect() 304 | 305 | if (!this.isFilterEnabled && !this.isTremoloEnabled) { 306 | this.noise.toDestination() 307 | } else if (!this.isFilterEnabled && this.isTremoloEnabled) { 308 | this.tremolo = new Tone.Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start() 309 | this.noise.connect(this.tremolo) 310 | } else if (this.isFilterEnabled && !this.isLFOFilterCutoffEnabled && !this.isTremoloEnabled) { 311 | this.filter = new Tone.Filter(this.filterCutoff, this.filterType).toDestination() 312 | this.noise.connect(this.filter) 313 | this.lfo.disconnect() 314 | this.lfo.stop() 315 | } else if (this.isFilterEnabled && this.isLFOFilterCutoffEnabled && !this.isTremoloEnabled) { 316 | this.filter = new Tone.Filter(this.filterCutoff, this.filterType).toDestination() 317 | this.noise.connect(this.filter) 318 | this.lfo = new Tone.LFO({ frequency: this.lfoFilterCutoffFrequency, min: this.lfoFilterCutoffRange[0], max: this.lfoFilterCutoffRange[1] }) 319 | this.lfo.connect(this.filter.frequency).start() 320 | } else if (this.isFilterEnabled && this.isLFOFilterCutoffEnabled && this.isTremoloEnabled) { 321 | this.tremolo = new Tone.Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start() 322 | this.filter = new Tone.Filter(this.filterCutoff, this.filterType).connect(this.tremolo) 323 | this.noise.connect(this.filter) 324 | this.lfo = new Tone.LFO({ frequency: this.lfoFilterCutoffFrequency, min: this.lfoFilterCutoffRange[0], max: this.lfoFilterCutoffRange[1] }) 325 | this.lfo.connect(this.filter.frequency).start() 326 | } else { 327 | this.tremolo = new Tone.Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start() 328 | this.filter = new Tone.Filter(this.filterCutoff, this.filterType).connect(this.tremolo) 329 | this.noise.connect(this.filter) 330 | } 331 | }, 332 | populateProfileItems (profileId) { 333 | this.$http.get('/profiles') 334 | .then(response => { 335 | if (response.status === 200) { 336 | if (response.data.profiles.length === 0) { 337 | this.addDefaultProfile() 338 | } else { 339 | this.profileItems = response.data.profiles 340 | if (profileId === 0) { 341 | this.selectedProfile = this.profileItems[0] 342 | } else { 343 | this.selectedProfile = this.profileItems.find(p => p.id === profileId) 344 | } 345 | this.exportedProfile = this.profileItems[0] 346 | this.recordedProfile = this.profileItems[0] 347 | this.loadProfile(true) 348 | } 349 | } 350 | }) 351 | }, 352 | addDefaultProfile () { 353 | this.$http.post('/profiles/default') 354 | .then(response => { 355 | if (response.status === 200) { 356 | const defaultProfile = { id: response.data.id, text: 'Default' } 357 | this.profileItems = [defaultProfile] 358 | this.selectedProfile = defaultProfile 359 | } 360 | }) 361 | }, 362 | saveProfile () { 363 | this.$http.post('/profiles', { 364 | name: this.profileName, 365 | isTimerEnabled: this.isTimerEnabled, 366 | duration: this.duration, 367 | volume: this.volume, 368 | noiseColor: this.noiseColor, 369 | isFilterEnabled: this.isFilterEnabled, 370 | filterType: this.filterType, 371 | filterCutoff: this.filterCutoff, 372 | isLFOFilterCutoffEnabled: this.isLFOFilterCutoffEnabled, 373 | lfoFilterCutoffFrequency: this.lfoFilterCutoffFrequency, 374 | lfoFilterCutoffLow: this.lfoFilterCutoffRange[0], 375 | lfoFilterCutoffHigh: this.lfoFilterCutoffRange[1], 376 | isTremoloEnabled: this.isTremoloEnabled, 377 | tremoloFrequency: this.tremoloFrequency, 378 | tremoloDepth: this.tremoloDepth, 379 | samples: this.loadedSamples 380 | }).then(response => { 381 | if (response.status === 200) { 382 | this.profileDialog = false 383 | this.populateProfileItems(response.data.id) 384 | this.unsavedWork = false 385 | this.infoSnackbarText = 'Profile Saved' 386 | this.infoSnackbar = true 387 | } 388 | }) 389 | .catch(() => { 390 | this.errorSnackbarText = 'Error Saving Profile' 391 | this.errorSnackbar = true 392 | }) 393 | }, 394 | updateProfile () { 395 | this.$http.put('/profiles/'.concat(this.selectedProfile.id), { 396 | isTimerEnabled: this.isTimerEnabled, 397 | duration: this.duration, 398 | volume: this.volume, 399 | noiseColor: this.noiseColor, 400 | isFilterEnabled: this.isFilterEnabled, 401 | filterType: this.filterType, 402 | filterCutoff: this.filterCutoff, 403 | isLFOFilterCutoffEnabled: this.isLFOFilterCutoffEnabled, 404 | lfoFilterCutoffFrequency: this.lfoFilterCutoffFrequency, 405 | lfoFilterCutoffLow: this.lfoFilterCutoffRange[0], 406 | lfoFilterCutoffHigh: this.lfoFilterCutoffRange[1], 407 | isTremoloEnabled: this.isTremoloEnabled, 408 | tremoloFrequency: this.tremoloFrequency, 409 | tremoloDepth: this.tremoloDepth, 410 | samples: this.loadedSamples 411 | }).then(response => { 412 | if (response.status === 200) { 413 | this.unsavedWork = false 414 | this.infoSnackbarText = 'Profile Saved' 415 | this.infoSnackbar = true 416 | } 417 | }) 418 | .catch(() => { 419 | this.errorSnackbarText = 'Error Saving Profile' 420 | this.errorSnackbar = true 421 | }) 422 | }, 423 | loadProfile (checkForUnsavedWork) { 424 | if (checkForUnsavedWork && this.unsavedWork) { 425 | this.confirmSwitchProfileDialog = true 426 | } else { 427 | this.$http.get('/profiles/'.concat(this.selectedProfile.id)) 428 | .then(response => { 429 | if (response.status === 200) { 430 | const profile = response.data.profile 431 | 432 | this.isTimerEnabled = profile.isTimerEnabled 433 | this.duration = profile.duration 434 | this.volume = profile.volume 435 | this.noiseColor = profile.noiseColor 436 | this.isFilterEnabled = profile.isFilterEnabled 437 | this.filterType = profile.filterType 438 | this.filterCutoff = profile.filterCutoff 439 | this.isLFOFilterCutoffEnabled = profile.isLFOFilterCutoffEnabled 440 | this.lfoFilterCutoffFrequency = profile.lfoFilterCutoffFrequency 441 | this.lfoFilterCutoffRange[0] = profile.lfoFilterCutoffLow 442 | this.lfoFilterCutoffRange[1] = profile.lfoFilterCutoffHigh 443 | this.isTremoloEnabled = profile.isTremoloEnabled 444 | this.tremoloFrequency = profile.tremoloFrequency 445 | this.tremoloDepth = profile.tremoloDepth 446 | 447 | this.loadedSamples = profile.samples 448 | 449 | this.activeProfile = profile 450 | 451 | if (this.unwatch) { 452 | this.unwatch() 453 | } 454 | 455 | this.unwatch = this.$watch('changeableSettings', function () { 456 | this.unsavedWork = true 457 | }) 458 | } 459 | }) 460 | .catch(() => { 461 | this.errorSnackbarText = 'Error Loading Profile' 462 | this.errorSnackbar = true 463 | }) 464 | } 465 | }, 466 | deleteProfile () { 467 | this.$http.delete('/profiles/'.concat(this.selectedProfile.id)) 468 | .then(response => { 469 | if (response.status === 200) { 470 | this.populateProfileItems(0) 471 | this.infoSnackbarText = 'Profile Deleted' 472 | this.infoSnackbar = true 473 | } 474 | }) 475 | .catch(() => { 476 | this.errorSnackbarText = 'Error Deleting Profile' 477 | this.errorSnackbar = true 478 | }) 479 | }, 480 | getSamples () { 481 | this.$http.get('/samples') 482 | .then(response => { 483 | if (response.status === 200) { 484 | this.allSamples = response.data.samples 485 | this.allSamples.forEach(s => { 486 | if (!this.players.has(s.id)) { 487 | this.players.add(s.id, '/samples/' + s.user + '_' + s.name).toDestination() 488 | } 489 | }) 490 | this.mainPlayLoading = false 491 | } 492 | }) 493 | }, 494 | uploadSample () { 495 | const formData = new FormData() 496 | 497 | formData.append('name', this.sampleName) 498 | formData.append('sample', this.selectedSample) 499 | 500 | this.$http.post('/samples', formData, { 501 | headers: { 502 | 'Content-Type': 'multipart/form-data' 503 | } 504 | }) 505 | .then(response => { 506 | if (response.status === 200) { 507 | this.getSamples() 508 | this.populatePreviewSampleItems() 509 | this.infoSnackbarText = 'Sample Uploaded' 510 | this.infoSnackbar = true 511 | } 512 | }) 513 | .catch((error) => { 514 | if (error.response.status === 409) { 515 | this.errorSnackbarText = 'Error Uploading Sample: Duplicate Sample Name' 516 | } else { 517 | this.errorSnackbarText = 'Error Uploading Sample' 518 | } 519 | this.errorSnackbar = true 520 | }) 521 | 522 | this.uploadSampleDialog = false 523 | }, 524 | addSample () { 525 | this.checkedSamples.forEach(i => { 526 | const load = this.allSamples.find(e => e.id === i) 527 | load.volume = -10 528 | load.sporadicMin = 30 529 | load.sporadicMax = 300 530 | this.loadedSamples.push(load) 531 | }) 532 | 533 | this.addSampleDialog = false 534 | this.checkedSamples = [] 535 | }, 536 | updateSampleVolume (id, index) { 537 | this.players.player(id).volume.value = this.loadedSamples[index].volume 538 | this.$forceUpdate() 539 | }, 540 | removeSample (index) { 541 | this.loadedSamples.splice(index, 1) 542 | }, 543 | getCurrentUser () { 544 | this.$http.get('/users/current') 545 | .then(response => { 546 | if (response.status === 200) { 547 | this.canUpload = response.data.user.canUpload 548 | this.$vuetify.theme.dark = response.data.user.darkMode 549 | const preferences = response.data.user.preferences 550 | this.$vuetify.theme.themes.dark.primary = preferences.accentColor.hex 551 | this.$vuetify.theme.themes.light.primary = preferences.accentColor.hex 552 | } 553 | }) 554 | }, 555 | resetProfileForm () { 556 | if (this.$refs.profileForm) { 557 | this.$refs.profileForm.reset() 558 | } 559 | }, 560 | resetUploadSampleForm () { 561 | if (this.$refs.uploadSampleForm) { 562 | this.$refs.uploadSampleForm.reset() 563 | } 564 | }, 565 | openImportDialog () { 566 | this.profileMoreDialog = false 567 | this.importDialog = true 568 | }, 569 | openExportDialog () { 570 | this.profileMoreDialog = false 571 | this.exportDialog = true 572 | }, 573 | async importProfile () { 574 | const fileContents = await this.readFile(this.importedProfile) 575 | const profileJSON = JSON.parse(fileContents) 576 | 577 | this.$http.post('/profiles/import', { 578 | name: this.importedProfileName, 579 | isTimerEnabled: profileJSON.isTimerEnabled, 580 | duration: profileJSON.duration, 581 | volume: profileJSON.volume, 582 | noiseColor: profileJSON.noiseColor, 583 | isFilterEnabled: profileJSON.isFilterEnabled, 584 | filterType: profileJSON.filterType, 585 | filterCutoff: profileJSON.filterCutoff, 586 | isLFOFilterCutoffEnabled: profileJSON.isLFOFilterCutoffEnabled, 587 | lfoFilterCutoffFrequency: profileJSON.lfoFilterCutoffFrequency, 588 | lfoFilterCutoffLow: profileJSON.lfoFilterCutoffLow, 589 | lfoFilterCutoffHigh: profileJSON.lfoFilterCutoffHigh, 590 | isTremoloEnabled: profileJSON.isTremoloEnabled, 591 | tremoloFrequency: profileJSON.tremoloFrequency, 592 | tremoloDepth: profileJSON.tremoloDepth 593 | }).then(response => { 594 | if (response.status === 200) { 595 | this.importDialog = false 596 | this.populateProfileItems(response.data.id) 597 | this.infoSnackbarText = 'Profile Imported and Saved' 598 | this.infoSnackbar = true 599 | } 600 | }) 601 | .catch(() => { 602 | this.errorSnackbarText = 'Error Importing Profile' 603 | this.errorSnackbar = true 604 | }) 605 | 606 | if (this.$refs.importForm) { 607 | this.$refs.importForm.reset() 608 | } 609 | }, 610 | readFile (file) { 611 | return new Promise((resolve, reject) => { 612 | const reader = new FileReader() 613 | 614 | reader.onload = res => { 615 | resolve(res.target.result) 616 | } 617 | reader.onerror = err => reject(err) 618 | 619 | reader.readAsText(file) 620 | }) 621 | }, 622 | exportProfile () { 623 | this.$http.get('/profiles/'.concat(this.exportedProfile.id)) 624 | .then(response => { 625 | if (response.status === 200) { 626 | const profile = response.data.profile 627 | 628 | const profileJSON = {} 629 | profileJSON.name = this.exportedProfile.text 630 | profileJSON.isTimerEnabled = profile.isTimerEnabled 631 | profileJSON.duration = profile.duration 632 | profileJSON.volume = profile.volume 633 | profileJSON.noiseColor = profile.noiseColor 634 | profileJSON.isFilterEnabled = profile.isFilterEnabled 635 | profileJSON.filterType = profile.filterType 636 | profileJSON.filterCutoff = profile.filterCutoff 637 | profileJSON.isLFOFilterCutoffEnabled = profile.isLFOFilterCutoffEnabled 638 | profileJSON.lfoFilterCutoffFrequency = profile.lfoFilterCutoffFrequency 639 | profileJSON.lfoFilterCutoffLow = profile.lfoFilterCutoffLow 640 | profileJSON.lfoFilterCutoffHigh = profile.lfoFilterCutoffHigh 641 | profileJSON.isTremoloEnabled = profile.isTremoloEnabled 642 | profileJSON.tremoloFrequency = profile.tremoloFrequency 643 | profileJSON.tremoloDepth = profile.tremoloDepth 644 | 645 | const dataStr = 'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(profileJSON)) 646 | const downloadAnchorNode = document.createElement('a') 647 | downloadAnchorNode.setAttribute('href', dataStr) 648 | downloadAnchorNode.setAttribute('download', profileJSON.name + '.json') 649 | document.body.appendChild(downloadAnchorNode) // required for firefox 650 | downloadAnchorNode.click() 651 | downloadAnchorNode.remove() 652 | } 653 | }) 654 | .catch(() => { 655 | this.errorSnackbarText = 'Error Exporting Profile' 656 | this.errorSnackbar = true 657 | }) 658 | 659 | this.exportDialog = false 660 | }, 661 | populatePreviewSampleItems () { 662 | this.$http.get('/samples') 663 | .then(response => { 664 | if (response.status === 200) { 665 | this.previewSampleItems = response.data.samples 666 | if (this.previewSampleItems.length > 0) { 667 | this.selectedPreviewSample = this.previewSampleItems[0] 668 | } 669 | } 670 | }) 671 | }, 672 | openEditSampleForm () { 673 | if (this.previewSampleItems.length > 0) { 674 | this.selectedPreviewSample = this.previewSampleItems[0] 675 | } 676 | this.loadPreviewSample() 677 | }, 678 | closeEditSampleForm () { 679 | this.editSampleDialog = false 680 | this.previewSampleLoading = true 681 | if (this.previewSamplePlaying) { 682 | this.previewSamplePlaying = false 683 | this.previewSampleButtonText = 'Preview Sample' 684 | this.samplePreviewPlayer.stop() 685 | } 686 | }, 687 | loadPreviewSample () { 688 | this.previewSampleLoading = true 689 | this.$http.get('/samples/'.concat(this.selectedPreviewSample.id)) 690 | .then(async response => { 691 | if (response.status === 200) { 692 | const sample = response.data.sample 693 | 694 | await this.samplePreviewPlayer.load('/samples/' + sample.user + '_' + sample.name) 695 | 696 | this.previewSampleFadeIn = sample.fadeIn 697 | this.previewSampleLoopPointsEnabled = sample.loopPointsEnabled 698 | if (sample.loopPointsEnabled) { 699 | this.previewSampleLoopStart = sample.loopStart 700 | this.previewSampleLoopEnd = sample.loopEnd 701 | this.samplePreviewPlayer.setLoopPoints(this.previewSampleLoopStart, this.previewSampleLoopEnd) 702 | } else { 703 | this.previewSampleLoopStart = 0 704 | this.previewSampleLoopEnd = 0 705 | } 706 | this.samplePreviewPlayer.fadeIn = this.previewSampleFadeIn 707 | this.previewSampleLength = this.samplePreviewPlayer.buffer.duration 708 | this.previewSampleLoading = false 709 | } 710 | }) 711 | }, 712 | updatePreviewSampleLoopPoints () { 713 | if (this.previewSampleLoopPointsEnabled) { 714 | this.samplePreviewPlayer.setLoopPoints(this.previewSampleLoopStart, this.previewSampleLoopEnd) 715 | } else { 716 | this.samplePreviewPlayer.setLoopPoints(0, this.samplePreviewPlayer.buffer.duration) 717 | } 718 | }, 719 | previewSample () { 720 | if (this.previewSamplePlaying) { 721 | this.previewSamplePlaying = false 722 | this.previewSampleButtonText = 'Preview Sample' 723 | this.samplePreviewPlayer.stop() 724 | } else { 725 | this.previewSamplePlaying = true 726 | this.previewSampleButtonText = 'Stop' 727 | this.samplePreviewPlayer.start() 728 | } 729 | }, 730 | editSample () { 731 | this.$http.put('/samples/'.concat(this.selectedPreviewSample.id), { 732 | fadeIn: this.previewSampleFadeIn, 733 | loopPointsEnabled: this.previewSampleLoopPointsEnabled, 734 | loopStart: this.previewSampleLoopStart, 735 | loopEnd: this.previewSampleLoopEnd 736 | }).then(response => { 737 | if (response.status === 200) { 738 | this.getSamples() 739 | 740 | // Update sample if it's already loaded in current profile 741 | const sample = this.loadedSamples.find(s => s.id === this.selectedPreviewSample.id) 742 | if (sample) { 743 | sample.fadeIn = this.previewSampleFadeIn 744 | sample.loopPointsEnabled = this.previewSampleLoopPointsEnabled 745 | sample.loopStart = this.previewSampleLoopStart 746 | sample.loopEnd = this.previewSampleLoopEnd 747 | } 748 | 749 | this.closeEditSampleForm() 750 | this.infoSnackbarText = 'Sample Saved' 751 | this.infoSnackbar = true 752 | } 753 | }) 754 | .catch(() => { 755 | this.errorSnackbarText = 'Error Saving Sample' 756 | this.errorSnackbar = true 757 | }) 758 | }, 759 | updatePreviewSamplePlayerFadeIn () { 760 | this.samplePreviewPlayer.fadeIn = this.previewSampleFadeIn 761 | }, 762 | updatePreviewSamplePlayerLoopPoints () { 763 | if (this.previewSampleLoopStart >= 0 && this.previewSampleLoopEnd <= this.previewSampleLength) { 764 | this.samplePreviewPlayer.setLoopPoints(this.previewSampleLoopStart, this.previewSampleLoopEnd) 765 | } 766 | }, 767 | openStartRecordingDialog () { 768 | this.startRecordingDialog = true 769 | this.profileMoreDialog = false 770 | }, 771 | startRecording () { 772 | // Save current profile before recording 773 | this.updateProfile() 774 | 775 | this.$http.get('/profiles/'.concat(this.recordedProfile.id)) 776 | .then(async response => { 777 | if (response.status === 200) { 778 | const profile = response.data.profile 779 | 780 | this.isTimerEnabled = profile.isTimerEnabled 781 | this.duration = profile.duration 782 | this.volume = profile.volume 783 | this.noiseColor = profile.noiseColor 784 | this.isFilterEnabled = profile.isFilterEnabled 785 | this.filterType = profile.filterType 786 | this.filterCutoff = profile.filterCutoff 787 | this.isLFOFilterCutoffEnabled = profile.isLFOFilterCutoffEnabled 788 | this.lfoFilterCutoffFrequency = profile.lfoFilterCutoffFrequency 789 | this.lfoFilterCutoffRange[0] = profile.lfoFilterCutoffLow 790 | this.lfoFilterCutoffRange[1] = profile.lfoFilterCutoffHigh 791 | this.isTremoloEnabled = profile.isTremoloEnabled 792 | this.tremoloFrequency = profile.tremoloFrequency 793 | this.tremoloDepth = profile.tremoloDepth 794 | 795 | this.loadedSamples = profile.samples 796 | 797 | this.startRecordingDialog = false 798 | this.recordingDialog = true 799 | this.recordingTimeElapsed = 0 800 | 801 | await this.recorder.start() 802 | this.recordingInterval = setInterval(() => this.recordingTimeElapsed++, 1000) 803 | this.playProfileForRecording() 804 | } 805 | }) 806 | .catch(() => { 807 | this.errorSnackbarText = 'Error Recording Profile' 808 | this.errorSnackbar = true 809 | }) 810 | }, 811 | playProfileForRecording () { 812 | this.playDisabled = true 813 | Tone.Transport.cancel() 814 | 815 | if (!this.isFilterEnabled && !this.isTremoloEnabled) { 816 | this.noise = new Tone.Noise({ volume: this.volume, type: this.noiseColor }).connect(this.recorder).toDestination() 817 | } else if (!this.isFilterEnabled && this.isTremoloEnabled) { 818 | this.tremolo = new Tone.Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).connect(this.recorder).toDestination().start() 819 | this.noise = new Tone.Noise({ volume: this.volume, type: this.noiseColor }).connect(this.tremolo) 820 | } else if (this.isFilterEnabled && !this.isTremoloEnabled) { 821 | this.filter = new Tone.Filter(this.filterCutoff, this.filterType).connect(this.recorder).toDestination() 822 | this.noise = new Tone.Noise({ volume: this.volume, type: this.noiseColor }).connect(this.filter) 823 | } else if (this.isFilterEnabled && this.isTremoloEnabled) { 824 | this.tremolo = new Tone.Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).connect(this.recorder).toDestination().start() 825 | this.filter = new Tone.Filter(this.filterCutoff, this.filterType).connect(this.tremolo) 826 | this.noise = new Tone.Noise({ volume: this.volume, type: this.noiseColor }).connect(this.filter) 827 | } else { 828 | this.tremolo = new Tone.Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).connect(this.recorder).toDestination().start() 829 | this.filter = new Tone.Filter(this.filterCutoff, this.filterType).connect(this.tremolo) 830 | this.noise = new Tone.Noise({ volume: this.volume, type: this.noiseColor }).connect(this.filter) 831 | } 832 | 833 | if (this.isLFOFilterCutoffEnabled) { 834 | this.lfo = new Tone.LFO({ frequency: this.lfoFilterCutoffFrequency, min: this.lfoFilterCutoffRange[0], max: this.lfoFilterCutoffRange[1] }) 835 | this.lfo.connect(this.filter.frequency).start() 836 | } 837 | 838 | this.loadedSamples.forEach(s => { 839 | this.players.player(s.id).loop = true 840 | this.players.player(s.id).fadeIn = s.fadeIn 841 | if (s.loopPointsEnabled) { 842 | this.players.player(s.id).setLoopPoints(s.loopStart, s.loopEnd) 843 | } else { 844 | this.players.player(s.id).setLoopPoints(0, this.players.player(s.id).buffer.duration) 845 | } 846 | this.players.player(s.id).volume.value = s.volume 847 | 848 | this.players.player(s.id).disconnect() 849 | if (s.reverbEnabled) { 850 | const reverb = new Tone.Reverb(s.reverbDecay).connect(this.recorder).toDestination() 851 | reverb.set({ preDelay: s.reverbPreDelay, wet: s.reverbWet }) 852 | this.players.player(s.id).connect(reverb) 853 | } else { 854 | this.players.player(s.id).connect(this.recorder).toDestination() 855 | } 856 | }) 857 | 858 | this.noise.sync().start(0) 859 | 860 | this.loadedSamples.forEach(s => { 861 | if (s.playbackMode === 'sporadic') { 862 | this.players.player(s.id).loop = false 863 | 864 | const maxInt = parseInt(s.sporadicMax, 10) 865 | const minInt = parseInt(s.sporadicMin, 10) 866 | const rand = Math.floor(Math.random() * (maxInt - minInt + 1) + minInt) 867 | 868 | s.initialSporadicPlayInterval = setInterval(() => this.playSporadicSample(s.id), rand * 1000) 869 | } else { 870 | this.players.player(s.id).loop = true 871 | this.players.player(s.id).unsync().sync().start(0) 872 | } 873 | }) 874 | 875 | Tone.Transport.start('+0.1') 876 | }, 877 | async stopRecording () { 878 | const recording = await this.recorder.stop() 879 | 880 | // Set active profile back to the selected one 881 | this.loadProfile(false) 882 | 883 | const url = URL.createObjectURL(recording) 884 | const anchor = document.createElement('a') 885 | anchor.download = this.recordingFileName + '.webm' 886 | anchor.href = url 887 | anchor.click() 888 | 889 | clearInterval(this.recordingInterval) 890 | 891 | this.loadedSamples.forEach(s => { 892 | if (s.playbackMode === 'sporadic') { 893 | clearInterval(s.initialSporadicPlayInterval) 894 | clearInterval(s.sporadicInterval) 895 | } 896 | }) 897 | 898 | this.recordingDialog = false 899 | this.stop() 900 | }, 901 | async cancelRecording () { 902 | await this.recorder.stop() 903 | 904 | // Set active profile back to the selected one 905 | this.loadProfile(false) 906 | 907 | clearInterval(this.recordingInterval) 908 | this.recordingDialog = false 909 | this.stop() 910 | }, 911 | discardChanges () { 912 | this.unsavedWork = false 913 | this.loadProfile(true) 914 | this.confirmSwitchProfileDialog = false 915 | }, 916 | saveChanges () { 917 | // Set active profile back to previously selected one before saving 918 | this.selectedProfile = this.profileItems.find(p => p.text === this.activeProfile.name) 919 | this.updateProfile() 920 | this.confirmSwitchProfileDialog = false 921 | } 922 | } 923 | } 924 | -------------------------------------------------------------------------------- /src/components/register.js: -------------------------------------------------------------------------------- 1 | export default { 2 | name: 'Register', 3 | 4 | data: () => ({ 5 | valid: false, 6 | name: '', 7 | username: '', 8 | password: '', 9 | rules: { 10 | required: v => !!v || 'Required' 11 | } 12 | }), 13 | methods: { 14 | register () { 15 | this.$http.post('/users', { 16 | name: this.name, 17 | username: this.username, 18 | password: this.password, 19 | isAdmin: 1, 20 | darkMode: 0, 21 | canUpload: 1 22 | }) 23 | .then(response => { 24 | if (response.status === 200) { 25 | this.$router.push('/login') 26 | } 27 | }) 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | import router from './router' 4 | import vuetify from './plugins/vuetify' 5 | import instance from './axios' 6 | 7 | Vue.prototype.$http = instance 8 | 9 | Vue.config.productionTip = false 10 | 11 | new Vue({ 12 | router, 13 | vuetify, 14 | render: h => h(App) 15 | }).$mount('#app') 16 | -------------------------------------------------------------------------------- /src/plugins/vuetify.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Vuetify from 'vuetify/lib' 3 | 4 | import colors from 'vuetify/lib/util/colors' 5 | 6 | Vue.use(Vuetify) 7 | 8 | export default new Vuetify({ 9 | theme: { 10 | themes: { 11 | light: { 12 | primary: colors.blueGrey 13 | }, 14 | dark: { 15 | primary: colors.blueGrey 16 | } 17 | } 18 | } 19 | }) 20 | -------------------------------------------------------------------------------- /src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import VueRouter from 'vue-router' 3 | import Home from '../views/HomeView.vue' 4 | import instance from '../axios' 5 | 6 | Vue.use(VueRouter) 7 | 8 | const routes = [ 9 | { 10 | path: '/', 11 | name: 'Home', 12 | component: Home 13 | }, 14 | { 15 | path: '/login', 16 | name: 'Login', 17 | component: () => import('../views/LoginView.vue') 18 | }, 19 | { 20 | path: '/register', 21 | name: 'Register', 22 | component: () => import('../views/RegisterView.vue') 23 | }, 24 | { 25 | path: '/admin', 26 | name: 'Admin', 27 | component: () => import('../views/AdminView.vue') 28 | }, 29 | { 30 | path: '/account', 31 | name: 'Account', 32 | component: () => import('../views/AccountView.vue') 33 | } 34 | ] 35 | 36 | const router = new VueRouter({ 37 | mode: 'history', 38 | base: process.env.BASE_URL, 39 | routes 40 | }) 41 | 42 | router.beforeEach((to, from, next) => { 43 | if (to.name === 'Home') { 44 | instance.get('/auth') 45 | .then(response => { 46 | if (response.status === 200) { 47 | next() 48 | } else { 49 | next('/register') 50 | } 51 | }) 52 | .catch(() => { 53 | next('/register') 54 | }) 55 | } else if (to.name === 'Admin') { 56 | instance.get('/admin') 57 | .then(response => { 58 | if (response.status === 200) { 59 | next() 60 | } else { 61 | next('/') 62 | } 63 | }) 64 | .catch(() => { 65 | next('/') 66 | }) 67 | } else if (to.name === 'Register') { 68 | instance.get('/setup') 69 | .then(response => { 70 | if (response.status !== 200 || !response.data.setup) { 71 | next('/login') 72 | } else { 73 | next() 74 | } 75 | }) 76 | .catch(() => { 77 | next('/login') 78 | }) 79 | } else if (to.name === 'Account') { 80 | instance.get('/auth') 81 | .then(response => { 82 | if (response.status === 200) { 83 | next() 84 | } else { 85 | next('/register') 86 | } 87 | }) 88 | .catch(() => { 89 | next('/register') 90 | }) 91 | } else { 92 | next() 93 | } 94 | }) 95 | 96 | export default router 97 | -------------------------------------------------------------------------------- /src/views/AccountView.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 16 | -------------------------------------------------------------------------------- /src/views/AdminView.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 16 | -------------------------------------------------------------------------------- /src/views/HomeView.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 16 | -------------------------------------------------------------------------------- /src/views/LoginView.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 16 | -------------------------------------------------------------------------------- /src/views/RegisterView.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 16 | -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | transpileDependencies: [ 3 | 'vuetify' 4 | ], 5 | devServer: { 6 | proxy: 'http://localhost:1432' 7 | } 8 | } 9 | --------------------------------------------------------------------------------