Exemplo n.º 1
0
	def convert_matrix_to_packet(self, matrix):
		# Music Mode INTENSITY
		if self.midi.buttons['music_mode_intensity']:
			rgb = [[0]*3 for x in range(3)] #[x[:] for x in [[0]*3]*3]

			# Scale the MIDI value to be within the slider ranges
			for i in range(len(matrix)):
				for j in range(len(self.midi.rgb[i])):
					rgb[i][j] = stabilize.scale(matrix[i], (Constants.MIN_INTENSITY, Constants.MAX_INTENSITY), (int(self.midi.settings['minimum']/Constants.MAX_INTENSITY * self.midi.rgb[i][j]), self.midi.rgb[i][j]))
					#print("knob %d %d" % (self.midi.midi_reader.knobs[6], int(self.midi.midi_reader.knobs[6]/254. * self.midi.midi_reader.rgb[i][j])))

			# update lights with new intensities
			self.midi.rgb = rgb
			self.update_lights()

		# Music Mode OFFSET
		if self.midi.buttons['music_mode_offset']:
			# map between minimum and offset
			offset = stabilize.scale(matrix[0], (Constants.MIN_INTENSITY, Constants.MAX_INTENSITY), (int(self.midi.settings['minimum']/Constants.MAX_INTENSITY * self.midi.settings['offset']), self.midi.settings['offset']))
			self.midi.settings['offset'] = offset

			# update lights with new offset
			self.update_lights()
Exemplo n.º 2
0
	def convert_data(self, matrix, mean, std):
		converted_matrix = [0] * len(matrix)
			
		for col in range(len(matrix)):
			# Calculate output pwm, where off is at some portion of the std below
			# the mean and full on is at some portion of the std above the mean.
			val = matrix[col] - mean[col] + 0.5 * std[col]
			val = val / (1.25 * std[col])
			if val > 1.0:
				val = 1.0
			elif val < 0:
				val = 0

			# Map the light values to be within the range of the MIDI light intensities
			converted_matrix[col] = stabilize.scale(val, (0.0, 1.0), (Constants.MIN_INTENSITY, Constants.MAX_INTENSITY))

		return converted_matrix