commit - 9c821de46cd4b91c557d2bf373fc52736265f51b
commit + 0712f059ee1ec6ff491448958ca7e420fe9ac061
blob - d004da54a975fc1b3aa808e5abaf547175964f1f
blob + 472d0caa0b7793da44af55bbcee2a2eee379af41
--- src/main/scala/twimpact/Midior.scala
+++ src/main/scala/twimpact/Midior.scala
package twimpact
import io.http.TwitterStream
-import javax.sound.midi.{Sequence, MidiSystem}
import trending.{MemoryBackend, Timescale, Trevor}
+import akka.actor.Scheduler
+import java.util.concurrent.TimeUnit
+import javax.sound.midi._
-
/**
* Hello world!
*
*/
object Midior extends App {
+ private final val PROGRAM = 192
+ private final val NOTEON = 144
+ private final val NOTEOFF = 128
+
+
val analyzer = new SimpleAnalyzer(new Trevor(new MemoryBackend), Seq(Timescale(300, 10), Timescale(60, 1)))
// Get default sequencer.
val sequencer = MidiSystem.getSequencer
sequencer.open()
+ def createEvent(t: Int, ch: Int, instr: Int, vel: Int, tick: Long) = {
+ val message = new ShortMessage
+ message.setMessage(t, ch, instr, vel)
+ new MidiEvent(message, tick)
+ }
+
+
val sequence = new Sequence(Sequence.PPQ, 10)
+ val track = sequence.createTrack
+
val sb = synthesizer.getDefaultSoundbank
val instruments = synthesizer.getDefaultSoundbank.getInstruments
synthesizer.loadInstrument(instruments(0))
password = "Ywnkmpw."
}
+ synthesizer.getDefaultSoundbank.getInstruments.zipWithIndex.foreach(println(_))
+ def findPatch(name: String) = synthesizer.getDefaultSoundbank.getInstruments.indexWhere(_.getName == name)
+
+
+ var channelMap: Map[String, (Int, Int)] = Map(
+ "en" -> (2, findPatch("Steel String Guitar")),
+ "id" -> (3, findPatch("Nylon Str Guitar")),
+ "ja" -> (4, findPatch("Shakuhachi")),
+ "es" -> (5, findPatch("Maracas")),
+ "nl" -> (6, findPatch("Fiddle")),
+ "pt" -> (7, findPatch("Tuned Drum")),
+ "it" -> (8, findPatch("Clean Guitar")),
+ "da" -> (9, findPatch("Seashore")),
+ "ko" -> (10, findPatch("Koto")),
+ "th" -> (11, findPatch("Sitar")),
+ "fr" -> (12, findPatch("Woodblock")),
+ "de" -> (13, findPatch("Steel Drums")),
+ "ar" -> (14, findPatch("Viola")),
+ "he" -> (15, findPatch("Clarinet"))
+ )
+
+ midiChannels(1).programChange(35)
+ channelMap.foreach {
+ case (language, (ch, instrument)) =>
+ midiChannels(ch).programChange(instrument)
+ }
+
stream.stream(Seq()) {
line =>
analyzer.tweet.fromJSON(line).foreach {
tweet =>
analyzer.analyze(tweet).foreach {
info =>
- if (info.score > 1.0) {
- println("score=%.2f rate=%.2f [user=%s, rank=%.2f] %s"
- .format(info.score, info.rate, info.rti.user, info.rank, info.rti.text))
- val note = 40 + info.score.toInt
- val reverb = 60 + info.rate.toInt
- midiChannels(1).noteOff(note)
- midiChannels(1).noteOn(note, reverb)
+ if (info.score > 0.5) {
+ println("%s: score=%.2f rate=%.2f [user=%s, rank=%.2f]"
+ .format(info.rti.detectedLanguages.head, info.score, info.rate, info.rti.user, info.rank))
+ info.rti.detectedLanguages.foreach {
+ fl =>
+ val note = (info.score * 5 + info.rank).toInt
+ val velocity = fl.coverage
+
+ val language = fl.code
+ val ch = channelMap.get(language).getOrElse((1,1))._1
+
+ if(ch == 1) {
+// midiChannels(ch).noteOn(9, 100)
+ } else {
+ midiChannels(ch).noteOn(note, velocity)
+ Scheduler.scheduleOnce({() => midiChannels(ch).noteOff(note)}, 2000, TimeUnit.MILLISECONDS)
+ }
+ }
}
}
}
blob - 0633fc1f48ccfa883718efa5927d1212481e0c9f
blob + c85e74328c0c222f2e94af12d4181a9424241e77
--- src/main/scala/twimpact/SimpleAnalyzer.scala
+++ src/main/scala/twimpact/SimpleAnalyzer.scala
package twimpact
import grizzled.slf4j.Logging
+import text.{FoundLanguage, LanguageSet}
import trending.{Timescale, TwimpactScore, MultiScaleTrend, Trevor}
import twitter.{RetweetInfo, Tweet, Twitter}
tweets.put(tweet.id, tweet)
tweetFifo.update(tweet.id)
+ if (rti.isNew) {
+ val l = languageDetector.detectLanguage(rti.text)
+ if (l.size >= 1 && l.head.coverage > 50) {
+ rti.detectedLanguages = l
+ } else {
+ val userLanguage =
+ if (tweet.retweetedStatus.isDefined && tweet.retweetedStatus.get.userLanguage.isDefined)
+ tweet.retweetedStatus.get.userLanguage.get
+ else
+ tweet.userLanguage.getOrElse("??")
+
+ rti.detectedLanguages = new LanguageSet(Seq(new FoundLanguage(userLanguage, 101))) + l
+ }
+ }
+ // make sure the tweet has detected languages
+ tweet.detectedLanguages = rti.detectedLanguages
+
val now = tweet.createdAt
retweetTrend.update(rti.key, now)
userRetweetTrend.update(rti.user, now)
- Some(MidiorInfo(rti, retweetTrend.score(rti.key), retweetTrend.rate(rti.key), twimpacts
- .computeTwimpact(rti.user)))
+ Some(MidiorInfo(
+ rti,
+ retweetTrend.score(rti.key),
+ retweetTrend.rate(rti.key),
+ twimpacts.computeTwimpact(rti.user)
+ ))
case None =>
None
}
blob - /dev/null
blob + 8c972527de5082888b84b00984be16d83b5858fe (mode 644)
--- /dev/null
+++ src/main/resources/logback.xml
+<!--
+ ~ Copyright (c) 2011 TWIMPACT UG (haftungsbeschraenkt). All rights reserved.
+ -->
+
+<configuration debug="false">
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <target>System.out</target>
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} %-5level [%20.20logger{20}] %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender">
+ <target>System.err</target>
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} %-5level [%20.20logger{20}] %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <root level="INFO">
+ <appender-ref ref="STDERR"/>
+ </root>
+</configuration>
\ No newline at end of file