Skip to content

Commit

Permalink
search method
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Michael committed Dec 3, 2011
1 parent e75ae0a commit e36fa95
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 31 deletions.
55 changes: 45 additions & 10 deletions app/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Knob = function(elemId, searchTerm)
var Knob = function(elemId, searchTerm, initialValue)
{
var elemId = elemId,
elem = $("#" + elemId),
Expand All @@ -10,14 +10,22 @@ var Knob = function(elemId, searchTerm)
height = elem.height(),
width = elem.width(),
radius = null,
initial = initialValue || 0,
colors = [
'26e000','51ef00','B8FF05','FFEA05','FFC60A',
'ff8607','ff7005', 'ff5f04','ff4f03','f83a00','ee2b00'
];
this.boost = 0;

return {


boost: 0,

getQS: function()
{
console.log(this);
return searchTerm;
},

draw: function()
{
elem.empty();
Expand Down Expand Up @@ -47,18 +55,19 @@ var Knob = function(elemId, searchTerm)
var colorBars = barsElem.find('.colorBar');

// Draw knob.
var that = this;
$("#" + elemId + " div.bars div.control").knobKnob({
snap : 10,
value: 0,
value: initial,
turn : function(ratio) {
var step = Math.round((ratio * steps) / 0.5);
var dialStep = Math.min(9, Math.round((ratio * steps) / 0.5));
that.boost = Math.min(2, Math.round((10 * (ratio * 2) / 0.5)) / 10);
colorBars.each(function(i, e) {
if (i >= step) {
if (i >= dialStep) {
$(e).css("backgroundColor", "black");
} else {
$(e).css("backgroundColor", $(e).attr("active-color"));
}

});

}
Expand All @@ -74,6 +83,7 @@ var App = function()
{
var knobs = [],
mainElem = $("#main"),
baseQS = "http://developer.echonest.com/api/v4/artist/search?api_key=N6E4NIOVYMTHNDM8J&format=json&results=100",
titleElem = $("#title");

return {
Expand All @@ -93,9 +103,13 @@ var App = function()
// Make and store knobs.
var proxied = $.proxy(function(i, e) {
var id = $(e).attr("id"),
term = id.split("-")[1];
knobs.push(new Knob(id, term));
console.log("h");
term = id.split("-")[1],
rnd = Math.random(),
init = 0;
if (rnd > 0.7) {
init = 90;
}
knobs.push(new Knob(id, term, init));
}, this);

$(".synthi-knob").each(proxied);
Expand All @@ -114,8 +128,29 @@ var App = function()
knobs: function()
{
return knobs;
},

search: function()
{
var i = 0,
qs = baseQS + "&mood=",
knobTerms = [];

for (i = 0; i < knobs.length; i++) {
knobTerms.push(knobs[i].getQS());
}

qs += knobTerms.join(",");

$.getJSON(qs).success(function(data) {
console.log(data);
});

}

};

};

exports.Knob = Knob;
exports.App = App;
1 change: 0 additions & 1 deletion app/spotify-metadata.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
sp = getSpotifyApi(1);
var _ = sp.require('libs/js/underscore')._;
var m = sp.require('sp://import/scripts/api/models');

Expand Down
18 changes: 5 additions & 13 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,20 @@
</div>
<div id="knob-rowdy" class="synthi-knob clearfix">
</div>
<div id="know-smooth" class="synthi-knob clearfix">
</div>
<div id="knob-alex" class="synthi-knob clearfix">
</div>
<div id="knob-fredrik" class="synthi-knob clearfix">
</div>
<div id="knob-alex1" class="synthi-knob clearfix">
</div>
<div id="knob-fredrik1" class="synthi-knob clearfix">
<div id="knob-smooth" class="synthi-knob clearfix">
</div>
</div>

<script src="libs/js/jquery.js"></script>
<script src="libs/js/underscore.js"></script>
<script src="libs/js/transform.js"></script>
<script src="libs/js/knobknob.jquery.js"></script>
<script src="app/app.js"></script>
<script>
$(function() {
var app = new App();
app.init().draw();
console.log("hi");
sp = getSpotifyApi(1);
var a = sp.require("app/app"),
app = a.App();
app.init().draw().search();
});
</script>
</body>
Expand Down
8 changes: 3 additions & 5 deletions libs/js/knobknob.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
<div class="base"></div>\
</div>';

return this.each(function(){

var el = $(this);
return this.each(function(i, e){
var el = $(e);
el.append(tpl);

var knob = $('.knob',el)
var knob = $('.knob',el),
knobTop = knob.find('.top'),
startDeg = -1,
currentDeg = 0,
Expand All @@ -41,7 +40,6 @@
}

knob.on('mousedown touchstart', function(e){
console.log(knob);
e.preventDefault();

var offset = knob.offset();
Expand Down
8 changes: 6 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
"36x18": "tutorial.png"
},
"AppName": {
"en": "Tutorial"
"en": "Mood Knobs"
},
"SupportedLanguages": [
"en"
],
"RequiredPermissions": ["http://*.spotify.com", "http://ws.audioscrobbler.com", "ws.audioscrobbler.com"]
"RequiredPermissions": ["http://*.spotify.com",
"http://ws.audioscrobbler.com",
"ws.audioscrobbler.com"
"http://developer.echonest.com",
"developer.echonest.com"]
}

0 comments on commit e36fa95

Please sign in to comment.