Пример #1
0
    def getVolume(self, rmsTarget=-15.0):
        """
        @param rmsTarget: the target RMS to adjust for, in dB.
        @type  rmsTarget: float

        @returns: the amount of dB to adjust by to reach the rmsTarget.
        @rtype:   float
        """
        ret = rmsTarget - self.rmsPercentile
        if ret > -self.peak:
            log.warning('trackmix', 'Track %r should be adjusted %r dB '
                'but only has headroom of %r dB',
                    self.name, ret, -self.peak)
            ret = -self.peak
        else:
            log.debug('trackmix', 'Track %r should have a %r dB adjustment',
                self.name, ret)

        return ret
Пример #2
0
def getSelecter(spec, stdout=None, database=None):
    """
    Parse a specification of a selecter to an actual selecter instance.

    @param spec:   a spec to parse
    @param stdout: a file object to output help to if needed

    @rtype: L{Selecter}
    """
    selecterArgs = []
    selecterClassName = spec

    if ':' in spec:
        selecterClassName, line = spec.split(':', 1)
        selecterArgs = line.split(':')
    selecterClass = reflect.namedAny(selecterClassName)
    parser = selecterClass.option_parser_class()
    log.debug('getSelecter', 'Creating selecter %r with args %r',
        selecterClass, selecterArgs)

    if 'help' in selecterArgs:
        if stdout:
            stdout.write('Options for selecter %s\n' % selecterClassName)
            parser.print_help(file=stdout)
        return None

    try:
        selOptions, selArgs = parser.parse_args(selecterArgs)
    except SystemExit:
        return None

    # FIXME: handle this nicer, too easy to hit
    if selArgs:
        print "WARNING: make sure you specify options with dashes"
        print "Did not parse %r" % selArgs

    return selecterClass(selOptions, database=database)
Пример #3
0
def init():
    externlog.init('DAD_DEBUG')
    externlog.setPackageScrubList('dad')
    externlog.debug('log', 'DAD logging initialized')
Пример #4
0
def main():

    from twisted.internet import reactor


    from twisted.internet import defer
    defer.Deferred.debug = 1

    log.init('DAD_DEBUG')
    log.logTwisted()
    log.debug('main', 'start')

    parser = optparse.OptionParser()
    parser.add_options(scouch.couchdb_option_list)
    parser.add_options(scouch.user_option_list)
    options, args = parser.parse_args()

    try:
        title = args[0]
    except:
        title = 'Love'

    # FIXME: allow customizing model and/or view(s)
    modelType = 'Couch'
    viewTypes = ['GTK', ]

    server = client.CouchDB(host=options.host, port=options.port)
    dbName = options.database
    db = daddb.DADDB(server, dbName)

    modelModule = 'dad%s.models.app.%sAppModel' % (modelType.lower(), modelType)
    amodel = reflect.namedAny(modelModule)(db)

    acontroller = app.AppController(amodel)

    for viewType in viewTypes:
        viewModule = 'dad%s.views.app.%sAppView' % (viewType.lower(), viewType)
        aview = reflect.namedAny(viewModule)()
        acontroller.addView(aview)

    # FIXME: gtk-specific
    aview.widget.connect('destroy', lambda _: reactor.stop())

    controller, model, views = acontroller.getTriad('Track')

    view = trackv.TrackView()
    view = views[0]

    aview.add(view)

    # start loading artists and albums

    d = defer.Deferred()

    # get the first track matching the arg for title
    
    # FIXME: add an exception for a missing view
    d.addCallback(lambda _:
        db.viewDocs('view-tracks-title', couch.Track, include_docs=True,
            startkey=title, endkey=title + 'Z'))
    def eb(failure):
        log.warningFailure(failure)
        print 'track.py: FAILURE: ', failure
        reactor.stop()
    d.addCallback(lambda g: list(g)[0].id)
    d.addCallback(lambda t: controller.populate(t, userName=options.user))
    d.addErrback(eb)


    d.callback(None)

    reactor.run()
Пример #5
0
def main():
    from twisted.internet import reactor

    from twisted.internet import defer
    defer.Deferred.debug = 1

    log.init('DAD_DEBUG')
    log.logTwisted()
    log.debug('main', 'start')

    parser = optparse.OptionParser()
    parser.add_options(couch.couchdb_option_list)
    options, args = parser.parse_args()

    # FIXME: allow customizing model and/or view(s)
    modelType = 'Couch'
    viewTypes = ['GTK', ]

    # this rebinds and makes it break in views
    # db = client.CouchDB('localhost', dbName='dad')
    cache = client.MemoryCache()
    server = client.CouchDB(host=options.host, port=options.port, cache=cache)
    dbName = options.database
    db = daddb.DADDB(server, dbName)


    # cache artists
    from dadcouch.model import couch as mcouch
    d = db.viewDocs('artists', mcouch.Artist)
    def cacheCb(_):
        print 'THOMAS: cache: hits %r lookups %r' % (
            db.db._cache.hits, db.db._cache.lookups)
    d.addCallback(cacheCb)

    modelModule = 'dad%s.models.app.%sAppModel' % (modelType.lower(), modelType)
    amodel = reflect.namedAny(modelModule)(db)

    acontroller = app.AppController(amodel)

    for viewType in viewTypes:
        viewModule = 'dad%s.views.app.%sAppView' % (viewType.lower(), viewType)
        aview = reflect.namedAny(viewModule)()
        acontroller.addView(aview)

    # FIXME: gtk-specific
    aview.widget.connect('destroy', lambda _: reactor.stop())


    vbox = gtk.VBox()

    hbox = gtk.HBox()

    vbox.add(hbox)

    aview.widget.add(vbox)

    artistView = views.ArtistSelectorView()
    artistModel = daddb.ArtistSelectorModel(db)
    artistController = selector.ArtistSelectorController(artistModel)
    artistController.addView(artistView)
    acontroller.add(artistController)
    hbox.pack_start(artistView)

    albumView = views.AlbumSelectorView()
    albumModel = daddb.AlbumSelectorModel(db)
    albumController = selector.AlbumSelectorController(albumModel)
    albumController.addView(albumView)
    acontroller.add(albumController)
    hbox.pack_start(albumView)

    trackView = scheduler.TracksUI(selector=True)
    trackModel = daddb.TrackSelectorModel(db)
    trackController = selector.TrackSelectorController(trackModel)
    acontroller.add(trackController)
    trackController.addView(trackView)

    vbox.add(trackView)

    aview.widget.show_all()


    # listen to changes on artist selection so we can filter the albums view
    def artist_selected_cb(self, ids):
        album_ids = []
        if ids:
            print 'THOMAS: selected artist ids', ids
            album_ids = albumModel.get_artists_albums(ids)
        albumView.set_album_ids(album_ids)

        trackView.set_artist_ids(ids)

    artistView.connect('selected', artist_selected_cb)

    def track_selected_cb(self, trackObj):
        w = gtk.Window()

        from dadgtk.views import track
        view = track.TrackView()

        w.add(view.widget)


        model = daddb.TrackModel(db)
        controller = trackc.TrackController(model)
        controller.addView(view)
        # FIXME: don't hardcode
        options.user = '******'
        d = controller.populate(trackObj.id, userName=options.user)
        d.addCallback(lambda _: w.set_title(trackObj.name))

        w.show_all()



 

    trackView.connect('clicked', track_selected_cb)

    # start loading artists and albums

    d = defer.Deferred()

    d.addCallback(lambda _: artistController.populate())
    d.addCallback(lambda _: albumController.populate())
    d.addCallback(lambda _: trackController.populate())
    d.addCallback(cacheCb)

    d.callback(None)

    reactor.run()