Fork me on GitHub

Wednesday, January 23, 2013

Scaloid powered Soundcorset metronome & tuner


I recently released all-in-one metronome and tuner application, called Soundcorset metronome & tuner. It covers all of the basic features required to metronomes and tuners, and I will grow it constantly.

Using Scaloid, the UI layout is written incredibly concise without any XML. For example, the image shown below is the screenshot of the main activity:


In "bpm" section, the code is written as:

this += new SLinearLayout {
  SButton("-", bpm -= 1).textSize(25 dip).<<(55 dip, FILL_PARENT).>>
  SButton("+", bpm += 1).textSize(25 dip).<<(55 dip, FILL_PARENT).>>
  this += new SVerticalLayout {
    STextView(R.string.bpm)
    bpmText = STextView().textSize(25 dip)
    latinBpmText = STextView("Allegro")
  }.<<.wrap.marginLeft(10 dip).>>
}.<<.>>

A simple 9 lines of code actually build the UI and wire the logic. Look at the statement "bpm -= 1" at the line 3. This simple and intuitive code actually play the beat a little slowly, move slidebar, and change the number indicates the bps. All these chores are hidden behind the assignment overload function:

def bpm_=(b: Int) {
  // move the progress bar and do more
}

Then Scala language permits fancy expressions such as "bpm += 10".

2 comments: