├── settings.gradle ├── art ├── 01.PNG ├── 02.PNG ├── 03.PNG └── 04.PNG ├── lib ├── jl1.0.1.jar ├── mp3spi1.9.5.jar └── tritonus_share.jar ├── src ├── META-INF │ └── MANIFEST.MF └── org │ └── ice1000 │ └── dekoder │ ├── data │ ├── Fact.kt │ └── PlayData.kt │ ├── utils │ ├── Echoer.kt │ ├── threads │ │ ├── PlayMusicThread.kt │ │ ├── ProgressThread.kt │ │ ├── PlayerRunSupporter.kt │ │ └── MPEGPlayThread.kt │ └── DSInputStreamReader.kt │ ├── decoders │ ├── DecoderInterface.kt │ ├── MIDIDecoder.kt │ ├── MP3Decoder.kt │ └── WAVDecoder.kt │ ├── factories │ └── SourceDataLineFactory.kt │ ├── database │ └── DatabaseManager.kt │ ├── gui │ ├── View.kt │ └── activity_main.fxml │ ├── cui │ └── CUIRunner.kt │ └── controllers │ ├── MainActivity.java │ └── MainActivityFramework.kt ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── res └── org │ └── ice1000 │ └── dekoder │ ├── res │ ├── kotlin.png │ └── css.css │ └── gui │ └── activity_main.fxml ├── .travis.yml ├── appveyor.yml ├── .gitignore ├── README-ZH.md ├── README.md ├── gradlew.bat ├── gradlew └── LICENSE /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'dekoder' 2 | -------------------------------------------------------------------------------- /art/01.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice1000/Dekoder/HEAD/art/01.PNG -------------------------------------------------------------------------------- /art/02.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice1000/Dekoder/HEAD/art/02.PNG -------------------------------------------------------------------------------- /art/03.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice1000/Dekoder/HEAD/art/03.PNG -------------------------------------------------------------------------------- /art/04.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice1000/Dekoder/HEAD/art/04.PNG -------------------------------------------------------------------------------- /lib/jl1.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice1000/Dekoder/HEAD/lib/jl1.0.1.jar -------------------------------------------------------------------------------- /lib/mp3spi1.9.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice1000/Dekoder/HEAD/lib/mp3spi1.9.5.jar -------------------------------------------------------------------------------- /lib/tritonus_share.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice1000/Dekoder/HEAD/lib/tritonus_share.jar -------------------------------------------------------------------------------- /src/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: org.ice1000.dekoder.gui.ViewKt 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice1000/Dekoder/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /res/org/ice1000/dekoder/res/kotlin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ice1000/Dekoder/HEAD/res/org/ice1000/dekoder/res/kotlin.png -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | language: java 3 | language: kotlin 4 | jdk: 5 | - oraclejdk8 6 | script: 7 | - "./gradlew assemble" 8 | - "./gradlew javadoc" 9 | - "./gradlew jar" 10 | before_install: 11 | - chmod a+x gradlew 12 | -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/data/Fact.kt: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.data 2 | 3 | /** 4 | * stores the fact data. 5 | * has not been used yet. 6 | * Created by ice1000 on 2016/5/19. 7 | */ 8 | 9 | data class Fact( 10 | val size: Int, 11 | var data: String 12 | ) -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/data/PlayData.kt: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.data 2 | 3 | /** 4 | * @author ice1000 5 | * Created by asus1 on 2016/5/29. 6 | */ 7 | 8 | data class PlayData( 9 | var isPaused: Boolean = false, 10 | var threadExit: Boolean = false 11 | ) -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | JAVA_HOME: C:\Program Files\Java\jdk1.8.0 3 | # 4 | 5 | build_script: 6 | - gradlew check --info 7 | - gradlew jar 8 | # 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Aug 15 19:00:22 MSK 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-bin.zip 7 | -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/utils/Echoer.kt: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.utils 2 | 3 | /** 4 | * @author ice1000 5 | * provides a #echo method to show messages on GUI form. 6 | * Created by ice1000 on 2016/5/23. 7 | */ 8 | 9 | interface Echoer { 10 | 11 | fun echo(msg: String) 12 | 13 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | out/production 3 | *.wav 4 | *.mp3 5 | save.db 6 | .idea/workspace.xml 7 | .idea/libraries 8 | /out/artifacts/dekoder/jfoenix.jar 9 | /out/artifacts/dekoder/kotlin-runtime.jar 10 | /out/artifacts/dekoder/dekoder.html 11 | *.jnlp 12 | .gradle/ 13 | build/ 14 | out/ 15 | .idea/ 16 | b.jar -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/decoders/DecoderInterface.kt: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.decoders 2 | 3 | import org.ice1000.dekoder.utils.DSInputStreamReader 4 | import org.ice1000.dekoder.utils.Echoer 5 | 6 | /** 7 | * Created by ice1000 on 2016/5/22. 8 | * 9 | * @author ice1000 10 | */ 11 | 12 | abstract class DecoderInterface(echoer: Echoer) : Echoer by echoer { 13 | 14 | protected abstract var reader: DSInputStreamReader 15 | abstract var path: String 16 | 17 | abstract fun onCreate() 18 | 19 | abstract fun onStart() 20 | 21 | abstract fun onStop() 22 | 23 | abstract fun onPause() 24 | 25 | open fun getTotalTime(): Long = 60 26 | } 27 | -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/factories/SourceDataLineFactory.kt: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.factories 2 | 3 | import javax.sound.sampled.AudioFormat 4 | import javax.sound.sampled.AudioSystem 5 | import javax.sound.sampled.DataLine 6 | import javax.sound.sampled.SourceDataLine 7 | 8 | /** 9 | * factory method to generate a line 10 | * Created by ice1000 on 2016/5/29. 11 | * 12 | * @author ice1000 13 | */ 14 | 15 | object SourceDataLineFactory { 16 | fun getLine(audioFormat: AudioFormat): SourceDataLine { 17 | val info = DataLine.Info(SourceDataLine::class.java, audioFormat) 18 | val res = AudioSystem.getLine(info) as SourceDataLine 19 | res.open(audioFormat) 20 | return res 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/utils/threads/PlayMusicThread.kt: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.utils.threads 2 | 3 | import org.ice1000.dekoder.data.PlayData 4 | import org.ice1000.dekoder.factories.SourceDataLineFactory 5 | import java.io.File 6 | import javax.sound.sampled.AudioSystem 7 | 8 | /** 9 | * @author ice1000 10 | * Created by asus1 on 2016/5/28. 11 | */ 12 | 13 | open class PlayMusicThread(fileToPlay: String) : Thread() { 14 | 15 | protected var ais = AudioSystem.getAudioInputStream(File(fileToPlay)) 16 | protected var format = ais.format 17 | protected var line = SourceDataLineFactory.getLine(format) 18 | 19 | var playData = PlayData() 20 | 21 | override fun run() = PlayerRunSupporter().run(playData, ais, line) 22 | } 23 | -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/database/DatabaseManager.kt: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.database 2 | 3 | import java.io.File 4 | 5 | /** 6 | * @author ice1000 7 | * d 8 | * Created by ice1000 on 2016/5/23. 9 | */ 10 | 11 | class DatabaseManager { 12 | 13 | private val saveFile = "save.db" 14 | private var file: File = File(saveFile) 15 | 16 | fun read(): List = file.readLines() 17 | 18 | /** 19 | * have got a built-in repeat check. 20 | */ 21 | fun write(path: String) { 22 | val b = read() 23 | if (path !in b) 24 | file.appendText(path + "\n", Charsets.UTF_8) 25 | println("path is $path") 26 | } 27 | 28 | init { 29 | file = File(saveFile) 30 | if (!file.exists()) 31 | file.createNewFile() 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /res/org/ice1000/dekoder/res/css.css: -------------------------------------------------------------------------------- 1 | /* Button */ 2 | .button { 3 | -fx-padding: 0.7em 0.57em; 4 | -fx-font-size: 14px; 5 | } 6 | 7 | .button-raised, .button-raised-fab { 8 | -fx-padding: 0.7em 0.57em; 9 | -fx-font-size: 14px; 10 | -fx-background-color: rgb(77, 102, 204); 11 | -fx-pref-width: 100; 12 | -fx-text-fill: WHITE; 13 | } 14 | 15 | .button-raised { 16 | -fx-button-type: FLAT; 17 | } 18 | 19 | .button-raised-fab { 20 | -fx-button-type: RAISED; 21 | -fx-background-color: rgb(255, 192, 63); 22 | -fx-border-radius: 50px; 23 | } 24 | 25 | /* Text */ 26 | .jfx-text-area, .text-area { 27 | -fx-font-weight: BOLD; 28 | -fx-background-color: rgb(137, 137, 137); 29 | -fx-border-radius: 20px; 30 | } 31 | 32 | .jfx-radio-button { 33 | -fx-stroke-width: 2px; 34 | -fx-fill: transparent; 35 | } 36 | 37 | .jfx-radio-button { 38 | -fx-fill: #0F9D58; 39 | } 40 | -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/utils/threads/ProgressThread.kt: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.utils.threads 2 | 3 | /** 4 | * @author ice1000 5 | * Created by ice1000 on 2016/5/25. 6 | */ 7 | 8 | class ProgressThread(private var setter: (Long) -> Unit) : Thread() { 9 | 10 | var running = true 11 | var nowTime = 0L 12 | 13 | /** 14 | * this variable stores the time when the song is stopped 15 | * test printing is deleted, because this prints too much information 16 | */ 17 | var storedTime: Long = 0L 18 | get() { 19 | return field + nowTime 20 | } 21 | 22 | override fun run() { 23 | running = true 24 | try { 25 | setter(storedTime) 26 | } catch(e: ArithmeticException) { 27 | return 28 | } 29 | val startTime = System.currentTimeMillis() 30 | while (running) { 31 | nowTime = System.currentTimeMillis() - startTime 32 | setter(storedTime) 33 | sleep(100) 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/gui/View.kt: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.gui 2 | 3 | import javafx.application.Application 4 | import javafx.fxml.FXMLLoader 5 | import javafx.scene.Parent 6 | import javafx.scene.Scene 7 | import javafx.stage.Stage 8 | import javafx.stage.StageStyle 9 | 10 | /** 11 | * @author ice1000 12 | * Created by ice1000 on 2016/5/21. 13 | */ 14 | 15 | class View : Application() { 16 | override fun start(primaryStage: Stage?) { 17 | // Thread(Runnable { 18 | // SVGGlyphLoader.loadGlyphsFont(View::class.java.getResourceAsStream("/src/view/res/kotlin.png"), "kotlin.png"); 19 | // }) 20 | val parent = FXMLLoader.load(View::class.java.getResource("activity_main.fxml")) 21 | 22 | val theScene = Scene(parent, 800.0, 600.0) 23 | primaryStage?.run { 24 | initStyle(StageStyle.DECORATED) 25 | scene = theScene 26 | title = "Dekoder by ice1000" 27 | isResizable = false 28 | show() 29 | } 30 | } 31 | 32 | fun onCreate() = launch(View::class.java) 33 | } 34 | 35 | fun main(args: Array) = View().onCreate() 36 | -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/utils/threads/PlayerRunSupporter.kt: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.utils.threads 2 | 3 | import org.ice1000.dekoder.data.PlayData 4 | import javax.sound.sampled.AudioInputStream 5 | import javax.sound.sampled.SourceDataLine 6 | 7 | /** 8 | * @author ice1000 9 | * Created by asus1 on 2016/7/1. 10 | */ 11 | 12 | class PlayerRunSupporter { 13 | 14 | companion object CONSTANTS { 15 | const val BUFFER_SIZE = 0x10000 16 | } 17 | 18 | fun run(playData: PlayData, ais: AudioInputStream, line: SourceDataLine) { 19 | try { 20 | line.open() 21 | } catch (e: Exception) { 22 | } 23 | line.start() 24 | var inBytes = 0 25 | var cnt = 0 26 | while (inBytes != -1 && !playData.threadExit) 27 | if (!playData.isPaused) { 28 | if (0 == cnt % 100) println("loop ${cnt++}") 29 | val audioData = ByteArray(BUFFER_SIZE) 30 | inBytes = ais.read(audioData, 0, BUFFER_SIZE) 31 | if (inBytes >= 0) 32 | line.write(audioData, 0, inBytes) 33 | } 34 | line.drain() 35 | line.close() 36 | println("Ended playing") 37 | } 38 | } -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/cui/CUIRunner.kt: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.cui 2 | 3 | import org.ice1000.dekoder.decoders.MP3Decoder 4 | import org.ice1000.dekoder.decoders.WAVDecoder 5 | import org.ice1000.dekoder.utils.Echoer 6 | import java.io.File 7 | import java.util.* 8 | 9 | /** 10 | * @author ice1000 11 | * Created by ice1000 on 2016/5/18. 12 | */ 13 | 14 | fun main(args: Array) { 15 | println("start") 16 | val a = System.currentTimeMillis() 17 | Thread.sleep(1000) 18 | println("a = ${System.currentTimeMillis() - a}") 19 | 20 | // val view = View() 21 | // view.onCreate() 22 | val path = File("save.db").run { 23 | try { 24 | readLines().first() 25 | } catch (e: Exception) { 26 | println("please input music file path :") 27 | val s = Scanner(System.`in`) 28 | s.nextLine() 29 | } 30 | } 31 | val decoder = CUIMP3Decoder(path) 32 | println(decoder.path) 33 | decoder.onStart() 34 | } 35 | 36 | class CUIWAVDecoder(fileName: String) : WAVDecoder(fileName, Printer()) 37 | class CUIMP3Decoder(fileName: String) : MP3Decoder(fileName, Printer()) 38 | 39 | class Printer : Echoer { 40 | override fun echo(msg: String) = println(msg) 41 | } 42 | -------------------------------------------------------------------------------- /README-ZH.md: -------------------------------------------------------------------------------- 1 | # Dekoder 2 | 3 | [![Build status](https://ci.appveyor.com/api/projects/status/e1oo252bbps4ffs2/branch/master?svg=true)](https://ci.appveyor.com/project/ice1000/dekoder/branch/master) 4 | [![Build Status](https://travis-ci.org/ice1000/Dekoder.svg?branch=master)](https://travis-ci.org/ice1000/Dekoder) 5 | [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0) 6 | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) 7 | 8 | ### 这是什么 9 | 这是一个音乐播放器。
10 | 使用Material Design的规范进行UI设计,使用纯Kotlin实现,不过GUI使用JavaFX。
11 | 12 | ### 语言 13 | + [English](./README.md) 14 | 15 | ![0](./art/04.PNG) 16 | 17 | ### 进度 18 | + [X] 读取元数据 19 | + [X] GUI 20 | + [X] 播放与停止 21 | + [X] 进度条 22 | + [X] 暂停 23 | + [X] 播放列表 24 | + [X] 刷新列表 25 | + [X] 上一首、下一首 26 | + [ ] 列表循环 27 | + [ ] 识别音频 28 | + [ ] 用于音频格式的DSL 29 | 30 | ### 用到的开源项目 31 | + [JFoenix](https://github.com/jfoenixadmin/JFoenix) 32 | 33 | ### 支持的格式 34 | + *.wav 35 | + *.mp3-低质量 (为此我高兴了好久!!!) 36 | 37 | ### 说明 38 | 一个Kotlin音乐播放器。使用纯Kotlin实现,不过和JavaFX的GUI接口是Java写的。
39 | 基于JavaSound实现音乐播放功能。
40 | 41 | ### 下载 运行 42 | 43 | 见 [release](https://github.com/ice1000/Dekoder/releases) 44 | -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/decoders/MIDIDecoder.kt: -------------------------------------------------------------------------------- 1 | //package decoders 2 | // 3 | //import org.ice1000.dekoder.utils.DSInputStreamReader 4 | //import org.ice1000.dekoder.utils.Echoer 5 | //import java.io.File 6 | //import javax.sound.midi.MidiSystem 7 | //import javax.sound.midi.Sequence 8 | //import javax.sound.midi.Sequencer 9 | // 10 | ///** 11 | // * @author ice1000 12 | // * TODO: implement midi decoding 13 | // * Created by ice1000 on 2016/5/24. 14 | // */ 15 | // 16 | //class MIDIDecoder : DecoderInterface { 17 | // 18 | // override var reader: DSInputStreamReader 19 | // override var path: String 20 | // private var seq: Sequence 21 | // private var seqr: Sequencer 22 | // 23 | // override fun play(): Unit = seqr.start() 24 | // 25 | // override fun init() = Unit 26 | // 27 | // override fun getTotalTime(): Long = 60L 28 | // 29 | // constructor(path: String, echoer: Echoer) : super(echoer) { 30 | // this.path = path 31 | // reader = DSInputStreamReader(File(path)) 32 | // 33 | // seq = MidiSystem.getSequence(File(path)) 34 | // seqr = MidiSystem.getSequencer() 35 | // seqr.open() 36 | // seqr.sequence = seq 37 | // seqr.addMetaEventListener { 38 | // if (it.type == 47) 39 | // println("done playing") 40 | // } 41 | // 42 | // } 43 | //} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dekoder 2 | 3 | [![Build status](https://ci.appveyor.com/api/projects/status/e1oo252bbps4ffs2/branch/master?svg=true)](https://ci.appveyor.com/project/ice1000/dekoder/branch/master) 4 | [![Build Status](https://travis-ci.org/ice1000/Dekoder.svg?branch=master)](https://travis-ci.org/ice1000/Dekoder) 5 | [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0) 6 | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) 7 | 8 | ### What is it 9 | This is a cross-platform music player.
10 | Materially Designed, and written in pure kotlin but with a javaFX GUI.
11 | 12 | ### Language 13 | + [简体中文](./README-ZH.md) 14 | 15 | ![0](./art/04.PNG) 16 | 17 | ### TODO list 18 | + [X] Read mata data. 19 | + [X] GUI 20 | + [X] Play and stop the media. 21 | + [X] Progress bar 22 | + [X] Pause 23 | + [X] Refresh list 24 | + [X] Next and previous song 25 | + [ ] List looping 26 | + [ ] Play list 27 | + [ ] Read the wave 28 | + [ ] Media format DSL 29 | 30 | ### Supported formats 31 | + *.wav 32 | + *.mp3-low-quality (this was so f#cking exciting!!!!) 33 | 34 | ### used open source projects 35 | + [JFoenix](https://github.com/jfoenixadmin/JFoenix) 36 | 37 | ### Description 38 | A kotlin music player.
39 | Dekoder is a desktop music player powered by JavaSound.
40 | Written in pure Kotlin but with a JavaFX GUI interface written in Java.
41 | 42 | ### Download & Run 43 | 44 | See [release](https://github.com/ice1000/Dekoder/releases) 45 | -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/utils/threads/MPEGPlayThread.kt: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.utils.threads 2 | 3 | import org.ice1000.dekoder.data.PlayData 4 | import org.ice1000.dekoder.factories.SourceDataLineFactory 5 | import org.tritonus.share.sampled.file.TAudioFileFormat 6 | import java.io.File 7 | import javax.sound.sampled.AudioFormat 8 | import javax.sound.sampled.AudioInputStream 9 | import javax.sound.sampled.AudioSystem 10 | import javax.sound.sampled.SourceDataLine 11 | 12 | /** 13 | * // MPEG1L3转PCM_SIGNED 14 | * Created by asus1 on 2016/5/29. 15 | * 16 | * @author ice1000 17 | */ 18 | class MPEGPlayThread(fileToPlay: String) : Thread() { 19 | 20 | private var file = File(fileToPlay) 21 | private var ais: AudioInputStream 22 | private var format: AudioFormat 23 | private var line: SourceDataLine 24 | 25 | var playData = PlayData() 26 | 27 | /** 28 | * I cannot get duration from properties so~ 29 | */ 30 | fun getDuration(): Long = (AudioSystem.getAudioFileFormat(file) as TAudioFileFormat) 31 | .properties()["duration"] as Long 32 | 33 | override fun run() { 34 | PlayerRunSupporter().run(playData, ais, line) 35 | } 36 | 37 | init { 38 | ais = AudioSystem.getAudioInputStream(file) 39 | format = ais.format 40 | if (format.encoding != AudioFormat.Encoding.PCM_SIGNED) { 41 | format = AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 42 | format.sampleRate, 43 | 16, 44 | format.channels, 45 | format.channels * 2, 46 | format.sampleRate, 47 | false 48 | ) 49 | ais = AudioSystem.getAudioInputStream(format, ais) 50 | } 51 | line = SourceDataLineFactory.getLine(format) 52 | } 53 | } -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/utils/DSInputStreamReader.kt: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.utils 2 | 3 | import java.io.File 4 | import java.io.FileInputStream 5 | 6 | /** 7 | * a domain specific input stream reader 8 | * @author ice1000 9 | * Created by ice1000 on 2016/5/19. 10 | */ 11 | 12 | class DSInputStreamReader(r: File) { 13 | private var index = 0 14 | var reader = FileInputStream(r) 15 | private set 16 | 17 | fun read(length: Int = 4, skip: Int = 0): ByteArray { 18 | val ba = ByteArray(length) 19 | reader.read(ba, 0, length) 20 | reader.read(ByteArray(skip), 0, skip) 21 | index += length 22 | index += skip 23 | return ba 24 | } 25 | 26 | fun readButSkipFirst(skip: Int = 2, length: Int = 0): ByteArray { 27 | reader.read(ByteArray(skip), 0, skip) 28 | return read(length) 29 | } 30 | 31 | fun readToString(length: Int = 4, skip: Int = 0) 32 | = String(read(length, skip)) 33 | 34 | fun readToStringButSkipFirst(skip: Int = 0, length: Int = 4) 35 | = String(readButSkipFirst(skip, length)) 36 | 37 | fun readToLong(length: Int = 4, skip: Int = 0): Long { 38 | val ba = read(length, skip) 39 | var ret: Long = 0 40 | var pow: Long = 1 41 | for (i in 0..length - 1) { 42 | val n = ba[i] * 1 43 | ret += pow * if (n >= 0) n else (0x100 + n) 44 | pow *= 0x100 45 | // println("ba[$i] = ${ba[i]}") 46 | // println("ret = $ret") 47 | // println("pow = $pow") 48 | } 49 | return ret 50 | } 51 | 52 | fun readToLongFromLast(length: Int = 4, skip: Int = 0): Long { 53 | val ba = read(length, skip) 54 | var ret: Long = 0 55 | var pow: Long = 1 56 | for (i in 0..length - 1) { 57 | val n = ba[length - 1 - i] * 1 58 | ret += pow * if (n >= 0) n else (0x100 + n) 59 | pow *= 0x100 60 | // println("ba[$i] = ${ba[i]}") 61 | // println("ret = $ret") 62 | // println("pow = $pow") 63 | } 64 | println("ret = $ret") 65 | return ret 66 | } 67 | 68 | /** 69 | * sometimes casting is inconvenient. 70 | */ 71 | fun readToInt(length: Int = 4, skip: Int = 0) 72 | = readToLong(length, skip).toInt() 73 | 74 | fun readToIntFromLast(length: Int = 4, skip: Int = 0) 75 | = readToLongFromLast(length, skip).toInt() 76 | } -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/controllers/MainActivity.java: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.controllers; 2 | 3 | import com.jfoenix.controls.JFXButton; 4 | import com.jfoenix.controls.JFXListView; 5 | import com.jfoenix.controls.JFXProgressBar; 6 | import org.ice1000.dekoder.decoders.DecoderInterface; 7 | import javafx.collections.ObservableList; 8 | import javafx.event.ActionEvent; 9 | import javafx.fxml.FXML; 10 | import javafx.scene.layout.AnchorPane; 11 | import org.jetbrains.annotations.NotNull; 12 | import org.ice1000.dekoder.utils.Echoer; 13 | 14 | import java.io.File; 15 | 16 | public class MainActivity extends MainActivityFramework { 17 | @FXML 18 | private JFXListView filesList; 19 | @FXML 20 | private JFXListView propertiesList; 21 | @FXML 22 | private AnchorPane window; 23 | @FXML 24 | private JFXButton playButton; 25 | @FXML 26 | private JFXProgressBar progressBar; 27 | private DecoderInterface dekoder; 28 | 29 | @FXML 30 | protected void playMusic(ActionEvent event) {super.playMusic();} 31 | 32 | @FXML 33 | protected void openFile(ActionEvent event) {showOpenFileDialog();} 34 | 35 | @Override 36 | protected void showOpenFileDialog() {openFile(getChooser().showOpenDialog(window.getScene().getWindow()));} 37 | 38 | @Override 39 | protected void openFile(@NotNull File file) {super.openFile(file);} 40 | 41 | @FXML 42 | protected void openHelp(ActionEvent event) {openGitHub();} 43 | 44 | @FXML 45 | protected void refreshList(ActionEvent event) {showFilesInTheSamePath(dekoder.getPath());} 46 | 47 | @Override 48 | protected void clearFilesShown() {filesList.getItems().remove(0, filesList.getItems().size());} 49 | 50 | @Override 51 | public DecoderInterface getDekoder() {return dekoder;} 52 | 53 | @Override 54 | public void setDekoder(DecoderInterface decoderInterface) {dekoder = decoderInterface;} 55 | 56 | @NotNull 57 | @Override 58 | protected JFXButton getPlayButton() {return playButton;} 59 | 60 | @Override 61 | public void setProgress(long i) {progressBar.setProgress(i / 1000.0 / dekoder.getTotalTime());} 62 | 63 | @FXML 64 | protected void stopPlaying(ActionEvent event) {super.stopPlaying();} 65 | 66 | @FXML 67 | protected void prevSong(ActionEvent event) {super.changeSong(false);} 68 | 69 | @FXML 70 | protected void nextSong(ActionEvent event) {super.changeSong(true);} 71 | 72 | @FXML 73 | protected void onDestroyed(ActionEvent event) {super.onDestroyed();} 74 | 75 | @NotNull 76 | @Override 77 | protected Echoer propertiesPrinter() {return msg -> propertiesList.getItems().add(msg);} 78 | 79 | @NotNull 80 | @Override 81 | protected Echoer filesPrinter() { 82 | return msg -> {ObservableList list = filesList.getItems(); if (!list.contains(msg)) list.add(msg);}; 83 | } 84 | 85 | @Override 86 | @FXML 87 | protected void initialize() {super.initialize();} 88 | 89 | @Override 90 | protected void clearPropertiesShown() {propertiesList.getItems().remove(0, propertiesList.getItems().size());} 91 | } 92 | -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/decoders/MP3Decoder.kt: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.decoders 2 | 3 | import org.ice1000.dekoder.utils.DSInputStreamReader 4 | import org.ice1000.dekoder.utils.Echoer 5 | import org.ice1000.dekoder.utils.threads.MPEGPlayThread 6 | import java.io.File 7 | 8 | /** 9 | * Created by ice1000 on 2016/5/26. 10 | * 11 | * @author ice1000 12 | */ 13 | open class MP3Decoder : DecoderInterface { 14 | 15 | private var playThread: MPEGPlayThread 16 | 17 | override fun onCreate() { 18 | } 19 | 20 | override fun onStart() { 21 | try { 22 | playThread.start() 23 | } catch(e: NullPointerException) { 24 | playThread = MPEGPlayThread(path) 25 | playThread.start() 26 | } catch(e: IllegalThreadStateException) { 27 | // 妈蛋线程异常抓错了 28 | playThread.playData.isPaused = false 29 | } 30 | // playThread.join() 31 | } 32 | 33 | override fun onStop() { 34 | try { 35 | playThread.playData.threadExit = true 36 | playThread.playData.isPaused = true 37 | playThread.join() 38 | } catch(e: Exception) { 39 | } 40 | } 41 | 42 | override fun onPause() { 43 | playThread.playData.isPaused = true 44 | // playThread.join() 45 | } 46 | 47 | override var reader: DSInputStreamReader 48 | override var path: String 49 | private var size: Long = 0 50 | 51 | // use the default initializer 52 | 53 | override fun getTotalTime(): Long { 54 | return playThread.getDuration() 55 | } 56 | 57 | @Suppress("ConvertSecondaryConstructorToPrimary") 58 | constructor(path: String, echoer: Echoer) : super(echoer) { 59 | this.path = path 60 | playThread = MPEGPlayThread(path) 61 | reader = DSInputStreamReader(File(path)) 62 | if ("ID3" == String(reader.read(3, 3))) { 63 | echo("ID3 not found") 64 | return 65 | } 66 | // ======================================================== 6 67 | size = reader.readToLong(4) 68 | echo("size = $size") 69 | // ======================================================== 10 70 | flag1@ while (true) { 71 | val flag = reader.readToString() 72 | val flagString = when (flag) { 73 | "TEXT" -> "text author:" 74 | "URL " -> "url:" 75 | "TCOP" -> "copyright:" 76 | "TOPE" -> "original artist:" 77 | "TCOM" -> "music author:" 78 | "TDAT" -> "date:" 79 | "TPE4" -> "translator:" 80 | "TPE3" -> "zhihui:" 81 | "TPE2" -> "band:" 82 | "TPE1" -> "artist:" 83 | "TSIZ" -> "size:" 84 | "TBLE" -> "zhuanji" 85 | "TIT2" -> "title:" 86 | "TIT3" -> "sub title" 87 | "TCON" -> "style:" 88 | "AENC" -> "encode tech:" 89 | "TBPM" -> "jiepai per second:" 90 | "TSSE" -> "encoder:" 91 | "TYER" -> "year:" 92 | "COMM" -> "comment:" 93 | else -> break@flag1 94 | } 95 | // 我偏要这样换行,你来打我呀 96 | val formatString = "$flagString " + 97 | reader.readToStringButSkipFirst(2, 98 | reader.readToIntFromLast()) 99 | // same part: every data is in the same format 100 | // if a flag is ignored, it will be println() here 101 | if (flag in listOf("TYER", "COMM")) 102 | println(formatString) 103 | else echo(formatString) 104 | } 105 | } 106 | } -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/decoders/WAVDecoder.kt: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.decoders 2 | 3 | import org.ice1000.dekoder.data.Fact 4 | import org.ice1000.dekoder.utils.DSInputStreamReader 5 | import org.ice1000.dekoder.utils.Echoer 6 | import org.ice1000.dekoder.utils.threads.PlayMusicThread 7 | import java.io.File 8 | 9 | /** 10 | * @author ice1000 11 | * decoder for wave files 12 | * Created by asus1 on 2016/5/22. 13 | */ 14 | 15 | open class WAVDecoder : DecoderInterface { 16 | 17 | override var reader: DSInputStreamReader 18 | private var channels: Int = 0 19 | private var size: Long = 0 20 | private var samplePSec: Int = 0 21 | private var bytePSec: Int = 0 22 | private var bytePSample: Int = 0 23 | private var bitPSample: Int = 0 24 | private var extraData: Int? = null 25 | private var fact: Fact? = null 26 | override var path: String 27 | 28 | private var playThread: PlayMusicThread 29 | 30 | override fun getTotalTime(): Long { 31 | try { 32 | return size / bytePSec 33 | } catch (e: Exception) { 34 | return 0 35 | } 36 | } 37 | 38 | override fun onCreate() { 39 | // sound = JavaSoundAudioClip(File(path).inputStream()) 40 | } 41 | 42 | override fun onStop() { 43 | try { 44 | playThread.playData.threadExit = true 45 | playThread.playData.isPaused = true 46 | playThread.join() 47 | } catch (e: Exception) { 48 | } 49 | // sound?.stop() 50 | } 51 | 52 | override fun onPause() { 53 | playThread.playData.isPaused = true 54 | // playThread.join() 55 | } 56 | 57 | override fun onStart() { 58 | try { 59 | playThread.start() 60 | } catch (e: NullPointerException) { 61 | playThread = PlayMusicThread(path) 62 | playThread.start() 63 | } catch (e: IllegalThreadStateException) { 64 | // 妈蛋线程异常抓错了 65 | playThread.playData.isPaused = false 66 | } 67 | // playThread.join() 68 | // sound?.play() 69 | } 70 | 71 | @Suppress("ConvertSecondaryConstructorToPrimary") 72 | constructor (fileName: String, echoer: Echoer) : super(echoer) { 73 | path = fileName 74 | playThread = PlayMusicThread(path) 75 | reader = DSInputStreamReader(File(path)) 76 | val metaSize = reader.readToInt(1, 3) 77 | // ======================================================== 0 78 | if ("RIFF" != reader.readToString()) { 79 | echo("warning: RIFF not found") 80 | return 81 | } 82 | // ======================================================== 4 83 | size = reader.readToLong() 84 | echo("size = $size") 85 | // ======================================================== 8 86 | if ("WAVE" != reader.readToString()) { 87 | echo("warning: WAVE not found") 88 | return 89 | } 90 | // ======================================================== 12 91 | if ("fmt " != reader.readToString()) { 92 | echo("fmt not found") 93 | echo("progress bar will not appear") 94 | return 95 | } 96 | // ======================================================== 16 97 | echo("metadata: $metaSize bytes") 98 | // ======================================================== 20 99 | echo("decoding: ${reader.readToLong(1, 1)}") 100 | // ======================================================== 22 101 | channels = reader.readToInt(1, 1) 102 | echo(if (channels == 1) "single" else "double" + " channel") 103 | // ======================================================== 24 104 | samplePSec = reader.readToInt() 105 | echo("$samplePSec samples per second") 106 | // ======================================================== 28 107 | bytePSec = reader.readToInt() 108 | echo("$bytePSec bytes per second") 109 | // ======================================================== 32 110 | bytePSample = reader.readToInt(2) 111 | echo("$bytePSample bytes per sample") 112 | // ======================================================== 34 113 | bitPSample = reader.readToInt(2) 114 | echo("$bitPSample bits per second") 115 | // ======================================================== 36 116 | extraData = if (metaSize == 18) reader.readToInt(2) else null 117 | echo("extra data: $extraData") 118 | // ======================================================== 36 or 38 119 | val s = reader.readToString() 120 | if ("fact" == s) { 121 | val a = reader.readToInt() 122 | val b = reader.readToString(a) 123 | fact = Fact(a, b) 124 | echo("FACT exists, values $b") 125 | // 把fact之后的data也读取一次 126 | reader.read() 127 | } else { 128 | // data已经读取过了,直接给fact赋值null 129 | fact = null 130 | echo("FACT does not exist") 131 | } 132 | // ======================================================== end 133 | // 现在读完了元数据 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /res/org/ice1000/dekoder/gui/activity_main.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 33 | 36 | 39 | 41 | 42 | 43 | 44 | 45 | 48 | 49 | 50 |
51 |
52 | 53 | 55 | 56 | 57 | 58 | 59 |
86 |
87 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/gui/activity_main.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 33 | 36 | 39 | 41 | 42 | 43 | 44 | 45 | 48 | 49 | 50 |
51 |
52 | 53 | 55 | 56 | 57 | 58 | 59 |
86 |
87 | -------------------------------------------------------------------------------- /src/org/ice1000/dekoder/controllers/MainActivityFramework.kt: -------------------------------------------------------------------------------- 1 | package org.ice1000.dekoder.controllers 2 | 3 | import com.jfoenix.controls.JFXButton 4 | import javafx.stage.FileChooser 5 | import org.ice1000.dekoder.database.DatabaseManager 6 | import org.ice1000.dekoder.decoders.DecoderInterface 7 | import org.ice1000.dekoder.decoders.MP3Decoder 8 | import org.ice1000.dekoder.decoders.WAVDecoder 9 | import org.ice1000.dekoder.utils.Echoer 10 | import org.ice1000.dekoder.utils.threads.ProgressThread 11 | import java.io.File 12 | import java.util.* 13 | import kotlin.concurrent.thread 14 | 15 | /** 16 | * @author ice1000 17 | * the framework of MainActivity 18 | * MainActivity is actually 19 | * Created by asus1 on 2016/5/22. 20 | */ 21 | 22 | abstract class MainActivityFramework { 23 | 24 | private val PAUSE = "Pause" 25 | private val PLAY = "Play" 26 | private val OPEN = "Open" 27 | private var fileList: ArrayList = ArrayList() 28 | 29 | abstract var dekoder: DecoderInterface? 30 | 31 | protected var manager = DatabaseManager() 32 | 33 | val chooser: FileChooser 34 | get() = FileChooser() 35 | 36 | private var progressThread = ProgressThread { setProgress(it) } 37 | 38 | private var progress = 0L 39 | 40 | private var stopped = false 41 | 42 | private var waiting = true 43 | set(value) { 44 | field = value 45 | if (!value) { 46 | println("waiting is set to be false") 47 | changeSong(true) 48 | } 49 | } 50 | 51 | open fun openGitHub() { 52 | Thread({ 53 | Runtime.getRuntime().exec( 54 | "rundll32 url.dll,FileProtocolHandler " + 55 | "https://github.com/ice1000/Dekoder") 56 | }).start() 57 | } 58 | 59 | /** 60 | * I think I`d better find a way to use less thread instances 61 | * this might take too much memory. 62 | * but I can only trust JVM`s GC now. : ) 63 | */ 64 | open protected fun playMusic() { 65 | println("playMusic in MainActivity called.") 66 | waiting = true 67 | if (PLAY == getPlayButton().text) { 68 | progressThread = ProgressThread( 69 | { setProgress(it) } 70 | ) 71 | try { 72 | if (stopped) { 73 | clearPropertiesShown() 74 | propertiesPrinter().echo(File(dekoder!!.path).name) 75 | dekoder = choose(dekoder!!.path) 76 | stopped = false 77 | } 78 | dekoder?.onStart() 79 | } catch (e: IllegalStateException) { 80 | return 81 | } 82 | if (progress > 0) 83 | progressThread.storedTime = progress 84 | progressThread.start() 85 | getPlayButton().text = PAUSE 86 | } else if (PAUSE == getPlayButton().text) { 87 | dekoder?.onPause() 88 | progress = progressThread.storedTime 89 | progressThread.running = false 90 | progressThread.join() 91 | getPlayButton().text = PLAY 92 | } else { 93 | // OPEN 94 | showOpenFileDialog() 95 | } 96 | } 97 | 98 | open protected fun stopPlaying() { 99 | println("stopPlaying in MainActivity called.") 100 | progress = 0 101 | if (!stopped) { 102 | stopped = true 103 | dekoder?.onStop() 104 | } 105 | getPlayButton().text = PLAY 106 | stop() 107 | } 108 | 109 | private fun stop() { 110 | progressThread.running = false 111 | progressThread.join() 112 | try { 113 | setProgress(progress) 114 | } catch(e: ArithmeticException) { 115 | setProgress(1) 116 | } 117 | } 118 | 119 | /** 120 | * @param i now time 121 | * this method will automatically divide i by the total time. 122 | * so just input the time which is already spent. 123 | */ 124 | abstract protected fun setProgress(i: Long) 125 | 126 | /** 127 | * because I have to set the text on the button 128 | * so MainActivity must provide this 129 | */ 130 | abstract protected fun getPlayButton(): JFXButton 131 | 132 | /** 133 | * get a printer to show information in the properties field.. 134 | * in the very beginning I used inner fun in this framework. 135 | * but to save code, I chose to implement this in the java interface. 136 | * because java8 supports lambda : ) 137 | */ 138 | abstract protected fun propertiesPrinter(): Echoer 139 | 140 | /** 141 | * the same as that one ↑ 142 | * get a printer to show information in the files field. 143 | */ 144 | abstract protected fun filesPrinter(): Echoer 145 | 146 | /** 147 | * to show a open file dialog 148 | */ 149 | abstract protected fun showOpenFileDialog() 150 | 151 | /** 152 | * select a decoders to decode the music file. 153 | * currently only WAVDecoder can work. 154 | */ 155 | protected fun choose(filePath: String): DecoderInterface { 156 | val p = propertiesPrinter() 157 | println(filePath) 158 | return if (filePath.endsWith("wav")) 159 | WAVDecoder(filePath, p) 160 | else if (filePath.endsWith("mp3")) 161 | MP3Decoder(filePath, p) 162 | // else if (filePath.endsWith("mid")) 163 | // MIDIDecoder(filePath, p) 164 | // else if (filePath.endsWith("ape")) 165 | // APEDecoder(filePath, p) 166 | else 167 | WAVDecoder(filePath, p) 168 | } 169 | 170 | /** 171 | * this will stop playing 172 | */ 173 | open protected fun openFile(file: File) { 174 | println("openFile in MainActivity called.") 175 | val path = file.path 176 | // stop the latest opened file 177 | try { 178 | stopPlaying() 179 | } catch (e: NullPointerException) { 180 | e.printStackTrace() 181 | } 182 | // echo the name of this file 183 | println("stopped.") 184 | clearPropertiesShown() 185 | propertiesPrinter() 186 | .echo(file.name) 187 | showFilesInTheSamePath(file.path) 188 | // write this file`s path to the database 189 | manager.write(path) 190 | println("written.") 191 | // give a value to dekoder, to choose a type 192 | dekoder = choose(path) 193 | println("written.") 194 | try { 195 | dekoder?.onCreate() 196 | } catch(e: Exception) { 197 | e.printStackTrace() 198 | } 199 | } 200 | 201 | open protected fun initialize() { 202 | println("initialize in MainActivity called.") 203 | try { 204 | openFile(File(manager.read()[0])) 205 | } catch (ignored: Exception) { 206 | getPlayButton().text = OPEN 207 | } 208 | } 209 | 210 | /** 211 | * @param path is the path of current file, not parent file 212 | * this will call the parent file automatically 213 | * and will clear the files which are already shown 214 | */ 215 | protected fun showFilesInTheSamePath(path: String) { 216 | println("showFilesInTheSamePath in MainActivity called.") 217 | clearFilesShown() 218 | fileList.removeAll(fileList) 219 | File(path).parentFile.list().forEach { 220 | if (it.endsWith("wav") || it.endsWith("mp3")) { 221 | filesPrinter().echo(it) 222 | fileList.add(it) 223 | } 224 | } 225 | } 226 | 227 | /** 228 | * change the current playing song 229 | * @param next true means go next, false means go previous 230 | */ 231 | protected fun changeSong(next: Boolean) { 232 | println("changeSong in MainActivity called.") 233 | val path = File(dekoder?.path) 234 | val currentFileIndex = fileList.indexOf(path.name) 235 | openFile(File( 236 | path.parent + File.separator + fileList[ 237 | (currentFileIndex 238 | + if (next) 1 else -1) 239 | % fileList.size 240 | ] 241 | )) 242 | playMusic() 243 | } 244 | 245 | /** 246 | * clear the files section which are shown 247 | * !!!attention!!! this is not properties section 248 | * this is files section!!!! 249 | */ 250 | protected abstract fun clearFilesShown() 251 | 252 | /** 253 | * clear the properties shown 254 | */ 255 | protected abstract fun clearPropertiesShown() 256 | 257 | /** 258 | * exit 259 | */ 260 | protected fun onDestroyed() = thread { 261 | try { 262 | stopPlaying() 263 | dekoder = null 264 | } catch(e: Exception) { 265 | } 266 | System.exit(0) 267 | } 268 | } 269 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------