Class: Reight::SoundEditor::Canvas
- Inherits:
-
Object
- Object
- Reight::SoundEditor::Canvas
- Includes:
- Hookable
- Defined in:
- lib/reight/app/sound/canvas.rb
Constant Summary collapse
- SEQUENCE_LEN =
32
- NOTE_HEIGHT =
3
Instance Attribute Summary collapse
-
#sound ⇒ Object
Returns the value of attribute sound.
-
#tone ⇒ Object
Returns the value of attribute tone.
-
#tool ⇒ Object
Returns the value of attribute tool.
Instance Method Summary collapse
- #begin_editing(&block) ⇒ Object
- #delete(x, y) ⇒ Object
- #end_editing ⇒ Object
-
#initialize(app) ⇒ Canvas
constructor
A new instance of Canvas.
- #note_pos_at(x, y) ⇒ Object
- #put(x, y) ⇒ Object
- #save ⇒ Object
- #sprite ⇒ Object
Methods included from Hookable
Constructor Details
Instance Attribute Details
#sound ⇒ Object
Returns the value of attribute sound.
20 21 22 |
# File 'lib/reight/app/sound/canvas.rb', line 20 def sound @sound end |
#tone ⇒ Object
Returns the value of attribute tone.
18 19 20 |
# File 'lib/reight/app/sound/canvas.rb', line 18 def tone @tone end |
#tool ⇒ Object
Returns the value of attribute tool.
18 19 20 |
# File 'lib/reight/app/sound/canvas.rb', line 18 def tool @tool end |
Instance Method Details
#begin_editing(&block) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/reight/app/sound/canvas.rb', line 31 def begin_editing(&block) @app.history.begin_grouping block.call if block ensure end_editing if block end |
#delete(x, y) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/reight/app/sound/canvas.rb', line 63 def delete(x, y) time_i, note_i = note_pos_at x, y note = @sound.at time_i, note_i return unless note remove_note time_i, note_i, note.tone @app.flash note_name y end |
#end_editing ⇒ Object
38 39 40 41 |
# File 'lib/reight/app/sound/canvas.rb', line 38 def end_editing() @app.history.end_grouping save end |
#note_pos_at(x, y) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/reight/app/sound/canvas.rb', line 43 def note_pos_at(x, y) sp = sprite notew = sp.w / SEQUENCE_LEN max = Reight::Sound::Note::MAX time_index = (x / notew).floor note_index = max - ((@scrolly + y) / NOTE_HEIGHT).floor return time_index, note_index.clamp(0, max) end |
#put(x, y) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/reight/app/sound/canvas.rb', line 52 def put(x, y) time_i, note_i = note_pos_at x, y @sound.each_note(time_index: time_i) .select {|note,| (note.index == note_i) != (note.tone == tone)} .each {|note,| remove_note time_i, note.index, note.tone} add_note time_i, note_i, tone @app.flash note_name y end |
#save ⇒ Object
27 28 29 |
# File 'lib/reight/app/sound/canvas.rb', line 27 def save() @app.project.save end |
#sprite ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/reight/app/sound/canvas.rb', line 73 def sprite() @sprite ||= RubySketch::Sprite.new.tap do |sp| pos = -> {return sp.mouse_x, sp.mouse_y} sp.draw {draw} sp.mouse_pressed {mouse_pressed( *pos.call, sp.)} sp.mouse_released {mouse_released(*pos.call, sp.)} sp.mouse_moved {mouse_moved( *pos.call)} sp.mouse_dragged {mouse_dragged( *pos.call, sp.)} sp.mouse_clicked {mouse_clicked( *pos.call, sp.)} end end |