Exemple #1
0
    def save(self, bundlepath, instances):
        addressings = {}

        # HMI
        for uri, addrs in self.hmi_addressings.items():
            addrs2 = []
            for addr in addrs['addrs']:
                addrs2.append({
                    'instance': instances[addr['instance_id']],
                    'port'    : addr['port'],
                    'label'   : addr['label'],
                    'minimum' : addr['minimum'],
                    'maximum' : addr['maximum'],
                    'steps'   : addr['steps'],
                })
            addressings[uri] = addrs2

        # Control Chain
        for uri, addrs in self.cc_addressings.items():
            addrs2 = []
            for addr in addrs:
                addrs2.append({
                    'instance': instances[addr['instance_id']],
                    'port'    : addr['port'],
                    'label'   : addr['label'],
                    'minimum' : addr['minimum'],
                    'maximum' : addr['maximum'],
                    'steps'   : addr['steps'],
                })
            addressings[uri] = addrs2

        # Write addressings to disk
        with TextFileFlusher(os.path.join(bundlepath, "addressings.json")) as fh:
            json.dump(addressings, fh)
Exemple #2
0
def save_last_bank_and_pedalboard(bank, pedalboard):
    if bank is None:
        return

    try:
        with TextFileFlusher(LAST_STATE_JSON_FILE) as fh:
            json.dump({'bank': bank - 1, 'pedalboard': pedalboard}, fh)
    except OSError:
        return
Exemple #3
0
    def save(self, bundlepath, instances):
        addressings = {}

        # HMI
        for uri, addrs in self.hmi_addressings.items():
            addrs2 = []
            for addr in addrs['addrs']:
                addrs2.append({
                    'instance': instances[addr['instance_id']],
                    'port': addr['port'],
                    'label': addr['label'],
                    'minimum': addr['minimum'],
                    'maximum': addr['maximum'],
                    'steps': addr['steps'],
                    'tempo': addr.get('tempo'),
                    'dividers': addr.get('dividers'),
                    'page': addr.get('page'),
                    'group': addr.get('group')
                })
            addressings[uri] = addrs2

        # Control Chain
        for uri, addrs in self.cc_addressings.items():
            addrs2 = []
            for addr in addrs:
                addrs2.append({
                    'instance': instances[addr['instance_id']],
                    'port': addr['port'],
                    'label': addr['label'],
                    'minimum': addr['minimum'],
                    'maximum': addr['maximum'],
                    'steps': addr['steps'],
                })
            addressings[uri] = addrs2

        # Virtual actuator (only /bpm for now)
        for uri, addrs in self.virtual_addressings.items():
            addrs2 = []
            for addr in addrs:
                addrs2.append({
                    'instance': instances[addr['instance_id']],
                    'port': addr['port'],
                    'label': addr['label'],
                    'minimum': addr['minimum'],
                    'maximum': addr['maximum'],
                    'steps': addr['steps'],
                    'tempo': addr.get('tempo'),
                    'dividers': addr.get('dividers'),
                    'page': addr.get('page')
                })
            addressings[uri] = addrs2

        # Write addressings to disk
        with TextFileFlusher(os.path.join(bundlepath,
                                          "addressings.json")) as fh:
            json.dump(addressings, fh, indent=4)
Exemple #4
0
    def _compare_and_set_value(self, key, value):
        if value == self.values[key]:
            return False
        self.changed = True
        self.values[key] = value

        with TextFileFlusher(self.INTERMEDIATE_PROFILE_PATH) as fh:
            json.dump(self.values, fh, indent=4)

        return True
Exemple #5
0
    def store(self, index):
        """Serialize the profile to JSON and store it on harddisk."""
        if index < 1 or index > 4:
            return False

        self.values['index'] = index

        # request and store mixer values
        fill_in_mixer_values(self.values)

        # save intermediate file first
        with TextFileFlusher(self.INTERMEDIATE_PROFILE_PATH) as fh:
            json.dump(self.values, fh, indent=4)

        # save real profile
        with TextFileFlusher(index_to_filepath(index)) as fh:
            json.dump(self.values, fh, indent=4)

        # done
        self.changed = False
        return True
Exemple #6
0
    def __init__(self, applyFn):
        self.applyFn = applyFn
        self.changed = False
        self.values  = self.DEFAULTS.copy()

        if os.path.exists(self.INTERMEDIATE_PROFILE_PATH):
            data = safe_json_load(self.INTERMEDIATE_PROFILE_PATH, dict)
            ensure_data_index_valid(data, 1)
            self.values.update(data)
        else:
            try:
                with TextFileFlusher(self.INTERMEDIATE_PROFILE_PATH) as fh:
                    json.dump(self.values, fh, indent=4)
            except IOError:
                pass

        fill_in_mixer_values(self.values)
        ioloop.IOLoop.instance().add_callback(self.apply_first)
Exemple #7
0
    def retrieve(self, index):
        """Deserialize the profile from JSON stored on harddisk."""
        if index < 1 or index > 4:
            return False

        # load state
        filename = index_to_filepath(index)
        if os.path.exists(filename):
            data = safe_json_load(filename, dict)
            data['index'] = index
        else:
            data = self.DEFAULTS.copy()
            data.update(self.DEFAULTS_EXTRA[index])

        self.changed = False
        self.values.update(data)

        # store everything in intermediate file, now with new values
        with TextFileFlusher(self.INTERMEDIATE_PROFILE_PATH) as fh:
            json.dump(self.values, fh, indent=4)

        # apply the values
        self.apply(False)
        return True
Exemple #8
0
 def save(self):
     with TextFileFlusher(PREFERENCES_JSON_FILE) as fh:
         json.dump(self.prefs, fh, indent=4)
Exemple #9
0
def save_banks(banks):
    with TextFileFlusher(BANKS_JSON_FILE) as fh:
        json.dump(banks, fh)