Skip to content

Commit

Permalink
Finish Expand and Tile patterns.
Browse files Browse the repository at this point in the history
  • Loading branch information
rec committed Jan 19, 2015
1 parent dc75f20 commit b5ff215
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 38 deletions.
2 changes: 1 addition & 1 deletion code/cpp/echomesh/color/Expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ FColorList expand(const FColorList& fcl, int xMult, int yMult, int columns)
for (auto y = 0; y < rows; ++y)
for (auto ym = 0; ym < yMult; ++ym)
for (auto x = 0; x < columns; ++x)
for (auto xm = 0; x < xMult; ++xm)
for (auto xm = 0; xm < xMult; ++xm)
result.push_back(fcl.get(y * rows + x));

return result;
Expand Down
23 changes: 21 additions & 2 deletions code/cpp/echomesh/component/InstrumentGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,32 @@ int InstrumentGrid::getLightCount() const {
return instruments_.size();
}

float InstrumentGrid::gamma() const {
MessageManagerLock l;
return gamma_;
}

void InstrumentGrid::setGamma(float gamma) {
MessageManagerLock l;
gamma_ = gamma;
useGamma_ = not near(gamma_, 1.0f);
}

void InstrumentGrid::setLights(const color::FColorList& colors) {
MessageManagerLock l;

auto size = jmin(colors.size(), instruments_.size());
for (auto i = 0; i < size; ++i) {
auto color = Colour(colors.get(i).argb());
instruments_[i]->setColor(color);
auto& c = colors.get(i);
uint32 argb;
if (useGamma_) {
auto c2 = c;
c2.gamma(gamma_);
argb = c2.argb();
} else {
argb = c.argb();
}
instruments_[i]->setColor(Colour(argb));
}

for (auto i = size; i < instruments_.size(); ++i)
Expand Down
5 changes: 4 additions & 1 deletion code/cpp/echomesh/component/InstrumentGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class InstrumentGrid : public Component {
void setBackground(const Colour&);
void setLayout(const Point& layout, const Point& size, const Point& padding,
const Point& instrumentPadding, const Point& labelPadding);
float gamma() const;
void setGamma(float gamma);

void paint(Graphics&);
void pythonRepaint();
Expand All @@ -38,6 +40,8 @@ class InstrumentGrid : public Component {
bool labelStartsAtZero_;
bool showLabel_;
Colour background_;
float gamma_ = 1.0f;
bool useGamma_ = false;

Point layout_;
Point size_;
Expand All @@ -53,4 +57,3 @@ class InstrumentGrid : public Component {
};

} // namespace echomesh

2 changes: 2 additions & 0 deletions code/cpp/echomesh/component/InstrumentGrid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ cdef extern from "echomesh/component/InstrumentGrid.h" namespace "echomesh":
void setShape(bool isRect)
void setShowLabel(bool)
int getLightCount()
float gamma()
void setGamma(float gamma)
9 changes: 8 additions & 1 deletion code/cpp/echomesh/component/LightingWindow.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ cdef class PyLightingWindow:
def __set__(self, bool visible):
self.thisptr.setVisible(visible)

property gamma:
def __get__(self):
return self.thisptr.grid().gamma()

def __set__(self, float gamma):
self.thisptr.grid().setGamma(gamma)

def dealloc(self):
deleteLightingWindow(self.thisptr)
self.thisptr = NULL
Expand All @@ -51,7 +58,7 @@ cdef class PyLightingWindow:
self.thisptr.grid().setShowLabel(show)

def set_label_starts_at_zero(self, bool at_zero):
self.thisptr.grid().setShowLabel(at_zero)
self.thisptr.grid().setLabelStartsAtZero(at_zero)

def set_layout(self, object layout, object size, object padding,
object instrument_padding, object label_padding):
Expand Down
1 change: 0 additions & 1 deletion code/cpp/echomesh/util/Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ bool near(Number x, Number y) {
return near(x, y, Number(0.000001));
}


} // namespace echomesh
20 changes: 2 additions & 18 deletions code/python/echomesh/output/Visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,8 @@ def update_callback(self):
self.brightness = self.transform.apply(self.brightness)

def emit_output(self, data):
first = getattr(self, 'first', not True)
if first and len(data) and len(data[0]):
print('---------------------------')
print('???', data[0])
for i, d in enumerate(data):
print(i, data)
print('---------------------------')
self.first = False
lights = cechomesh.combine_color_lists(data, columns=self.columns)

if first and len(lights):
print('two! ---------------------------')
for i, d in enumerate(data):
print(i, data)
print(lights)
print('---------------------------')
self.first = False

lights = cechomesh.combine_color_lists(data)
lights.columns = self.columns
lights.scale(self.brightness)
self.lighting_window.set_lights(lights)

Expand Down
5 changes: 3 additions & 2 deletions code/python/echomesh/pattern/Expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ class Expand(Filter):
},
}

def _evaluate_one(self, color):
return cechomesh.expand_color_list(colors, *self.get(scale))
def _evaluate_one(self, colors):
res = cechomesh.expand_color_list(colors, *self.get('scale'))
return res
2 changes: 1 addition & 1 deletion code/python/echomesh/pattern/Pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ class Filter(Pattern):
def _evaluate(self):
color_lists = self.patterns()
assert len(color_lists) == 1
self._evaluate_one(color_lists[0])
return self._evaluate_one(color_lists[0])
4 changes: 0 additions & 4 deletions code/python/echomesh/pattern/Scroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,4 @@ def _evaluate(self):
color_list, self.get('dx'), self.get('dy'), columns=columns,
wrap=self.get('wrap'), smooth=self.get('smooth'),
transform=self.get('transform'))
global LAST_LIST
if False and result != LAST_LIST:
LAST_LIST = result
print(result, color_list)
return result
3 changes: 0 additions & 3 deletions code/python/echomesh/pattern/Text.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,4 @@ def _evaluate(self):
raise ValueError("Text doesn't have a text setting")

image, width, height = draw_text(fontfile, text, height, font_height)
if debug:
print('width=%d, height=%d' % (width, height))
image.show()
return cechomesh.ColorList(image, columns=width)
8 changes: 4 additions & 4 deletions data/master/score/expand.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ type: sequence
pattern:
expand:
type: expand
scale =
spread:
type: spread
colors: [red, yellow]
scale: [10, 10]
pattern:
type: list
colors: [black, white]

elements:
-
Expand Down
21 changes: 21 additions & 0 deletions data/master/score/scroll-tile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
type: sequence

pattern:
scroll:
type: scroll
wrap: true
dx: system.elapsed
pattern:
type: tile
scale: [2, 2]
pattern:
type: expand
scale: [4, 6]
pattern:
type: list
colors: [black, white]

elements:
-
type: pattern
pattern: scroll
17 changes: 17 additions & 0 deletions data/master/score/tile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
type: sequence

pattern:
tile:
type: tile
scale: [2, 2]
pattern:
type: expand
scale: [4, 4]
pattern:
type: list
colors: [red, yellow]

elements:
-
type: pattern
pattern: tile

0 comments on commit b5ff215

Please sign in to comment.