Created
May 30, 2016 18:53
-
-
Save meghprkh/38067896f6fec003268a684905ec3aef to your computer and use it in GitHub Desktop.
Guitar Tuner JSX GTK demo output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******/ (function(modules) { // webpackBootstrap | |
/******/ // The module cache | |
/******/ var installedModules = {}; | |
/******/ // The require function | |
/******/ function __webpack_require__(moduleId) { | |
/******/ // Check if module is in cache | |
/******/ if(installedModules[moduleId]) | |
/******/ return installedModules[moduleId].exports; | |
/******/ // Create a new module (and put it into the cache) | |
/******/ var module = installedModules[moduleId] = { | |
/******/ exports: {}, | |
/******/ id: moduleId, | |
/******/ loaded: false | |
/******/ }; | |
/******/ // Execute the module function | |
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | |
/******/ // Flag the module as loaded | |
/******/ module.loaded = true; | |
/******/ // Return the exports of the module | |
/******/ return module.exports; | |
/******/ } | |
/******/ // expose the modules object (__webpack_modules__) | |
/******/ __webpack_require__.m = modules; | |
/******/ // expose the module cache | |
/******/ __webpack_require__.c = installedModules; | |
/******/ // __webpack_public_path__ | |
/******/ __webpack_require__.p = ""; | |
/******/ // Load entry module and return exports | |
/******/ return __webpack_require__(0); | |
/******/ }) | |
/************************************************************************/ | |
/******/ ([ | |
/* 0 */ | |
/***/ function(module, exports, __webpack_require__) { | |
'use strict'; | |
var _lib = __webpack_require__(1); | |
var Gtk = imports.gi.Gtk; | |
var Gst = imports.gi.Gst; | |
var Mainloop = imports.mainloop; | |
Gtk.init(null, 0); | |
Gst.init(null, 0); | |
var frequencies = { E: 329.63, A: 440, D: 587.33, G: 783.99, B: 987.77, e: 1318.5 }; | |
function playSound(frequency) { | |
var pipeline = new Gst.Pipeline({ name: 'note' }); | |
var source = Gst.ElementFactory.make('audiotestsrc', 'source'); | |
var sink = Gst.ElementFactory.make('autoaudiosink', 'output'); | |
source.set_property('freq', frequency); | |
pipeline.add(source); | |
pipeline.add(sink); | |
source.link(sink); | |
pipeline.set_state(Gst.State.PLAYING); | |
Mainloop.timeout_add(500, function () { | |
pipeline.set_state(Gst.State.NULL); | |
return false; | |
}); | |
} | |
var repr = (0, _lib.dom)( | |
'window', | |
{ title: 'Guitar Tuner', border_width: 100, signals: { destroy: function destroy() { | |
return Gtk.main_quit(); | |
} } }, | |
(0, _lib.dom)( | |
'buttonBox', | |
{ spacing: 10, orientation: Gtk.Orientation.VERTICAL }, | |
(0, _lib.dom)('button', { label: 'E', signals: { clicked: function clicked() { | |
return playSound(frequencies.E); | |
} } }), | |
(0, _lib.dom)('button', { label: 'A', signals: { clicked: function clicked() { | |
return playSound(frequencies.A); | |
} } }), | |
(0, _lib.dom)('button', { label: 'D', signals: { clicked: function clicked() { | |
return playSound(frequencies.D); | |
} } }), | |
(0, _lib.dom)('button', { label: 'G', signals: { clicked: function clicked() { | |
return playSound(frequencies.G); | |
} } }), | |
(0, _lib.dom)('button', { label: 'B', signals: { clicked: function clicked() { | |
return playSound(frequencies.B); | |
} } }), | |
(0, _lib.dom)('button', { label: 'e', signals: { clicked: function clicked() { | |
return playSound(frequencies.e); | |
} } }) | |
) | |
); | |
var guitarwindow = (0, _lib.render)(repr); | |
Gtk.main(); | |
/***/ }, | |
/* 1 */ | |
/***/ function(module, exports, __webpack_require__) { | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.dom = dom; | |
exports.render = render; | |
var Gtk = imports.gi.Gtk; | |
var objectOmit = __webpack_require__(2); | |
var window = 'window'; | |
var button = 'button'; | |
var buttonBox = 'buttonBox'; | |
function dom(element, attributes) { | |
for (var _len = arguments.length, children = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | |
children[_key - 2] = arguments[_key]; | |
} | |
return { | |
element: element, | |
attributes: objectOmit(attributes, 'signals'), | |
children: children, | |
signals: attributes.signals | |
}; | |
} | |
function render(vdom) { | |
var el; | |
switch (vdom.element) { | |
case window: | |
el = new Gtk.Window(vdom.attributes); | |
if (vdom.children) vdom.children.map(function (child) { | |
return el.add(render(child, el)); | |
}); | |
el.show(); | |
break; | |
case buttonBox: | |
el = new Gtk.ButtonBox(vdom.attributes); | |
if (vdom.children) vdom.children.map(function (child) { | |
return el.add(render(child, el)); | |
}); | |
el.show_all(); | |
break; | |
case button: | |
el = new Gtk.Button(vdom.attributes); | |
break; | |
} | |
if (vdom.signals) Object.keys(vdom.signals).map(function (signal) { | |
return el.connect(signal, vdom.signals[signal]); | |
}); | |
return el; | |
} | |
/***/ }, | |
/* 2 */ | |
/***/ function(module, exports, __webpack_require__) { | |
/*! | |
* object.omit <https://github.com/jonschlinkert/object.omit> | |
* | |
* Copyright (c) 2014-2015, Jon Schlinkert. | |
* Licensed under the MIT License. | |
*/ | |
'use strict'; | |
var isObject = __webpack_require__(3); | |
var forOwn = __webpack_require__(4); | |
module.exports = function omit(obj, keys) { | |
if (!isObject(obj)) return {}; | |
var keys = [].concat.apply([], [].slice.call(arguments, 1)); | |
var last = keys[keys.length - 1]; | |
var res = {}, fn; | |
if (typeof last === 'function') { | |
fn = keys.pop(); | |
} | |
var isFunction = typeof fn === 'function'; | |
if (!keys.length && !isFunction) { | |
return obj; | |
} | |
forOwn(obj, function (value, key) { | |
if (keys.indexOf(key) === -1) { | |
if (!isFunction) { | |
res[key] = value; | |
} else if (fn(value, key, obj)) { | |
res[key] = value; | |
} | |
} | |
}); | |
return res; | |
}; | |
/***/ }, | |
/* 3 */ | |
/***/ function(module, exports) { | |
/*! | |
* is-extendable <https://github.com/jonschlinkert/is-extendable> | |
* | |
* Copyright (c) 2015, Jon Schlinkert. | |
* Licensed under the MIT License. | |
*/ | |
'use strict'; | |
module.exports = function isExtendable(val) { | |
return typeof val !== 'undefined' && val !== null | |
&& (typeof val === 'object' || typeof val === 'function'); | |
}; | |
/***/ }, | |
/* 4 */ | |
/***/ function(module, exports, __webpack_require__) { | |
/*! | |
* for-own <https://github.com/jonschlinkert/for-own> | |
* | |
* Copyright (c) 2014-2016, Jon Schlinkert. | |
* Licensed under the MIT License. | |
*/ | |
'use strict'; | |
var forIn = __webpack_require__(5); | |
var hasOwn = Object.prototype.hasOwnProperty; | |
module.exports = function forOwn(o, fn, thisArg) { | |
forIn(o, function(val, key) { | |
if (hasOwn.call(o, key)) { | |
return fn.call(thisArg, o[key], key, o); | |
} | |
}); | |
}; | |
/***/ }, | |
/* 5 */ | |
/***/ function(module, exports) { | |
/*! | |
* for-in <https://github.com/jonschlinkert/for-in> | |
* | |
* Copyright (c) 2014-2016, Jon Schlinkert. | |
* Licensed under the MIT License. | |
*/ | |
'use strict'; | |
module.exports = function forIn(o, fn, thisArg) { | |
for (var key in o) { | |
if (fn.call(thisArg, o[key], key, o) === false) { | |
break; | |
} | |
} | |
}; | |
/***/ } | |
/******/ ]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment