musicality 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/ChangeLog.md +27 -1
 - data/README.md +153 -10
 - data/bin/collidify +102 -0
 - data/bin/lilify +57 -29
 - data/bin/midify +64 -24
 - data/bin/musicality +39 -0
 - data/examples/composition/auto_counterpoint.rb +4 -5
 - data/examples/composition/part_generator.rb +8 -2
 - data/examples/composition/scale_exercise.rb +1 -1
 - data/examples/notation/notes.rb +27 -0
 - data/examples/notation/parts.rb +51 -0
 - data/examples/notation/scores.rb +38 -0
 - data/examples/notation/twinkle.rb +34 -0
 - data/examples/notation/twinkle.score +33 -0
 - data/lib/musicality.rb +46 -11
 - data/lib/musicality/composition/dsl/score_dsl.rb +2 -2
 - data/lib/musicality/composition/dsl/score_methods.rb +10 -7
 - data/lib/musicality/notation/conversion/change_conversion.rb +1 -1
 - data/lib/musicality/notation/conversion/note_time_converter.rb +6 -23
 - data/lib/musicality/notation/conversion/score_conversion.rb +15 -15
 - data/lib/musicality/notation/conversion/score_converter.rb +50 -67
 - data/lib/musicality/notation/model/articulations.rb +3 -2
 - data/lib/musicality/notation/model/change.rb +15 -6
 - data/lib/musicality/notation/model/dynamics.rb +11 -8
 - data/lib/musicality/notation/model/instrument.rb +61 -0
 - data/lib/musicality/notation/model/instruments.rb +111 -0
 - data/lib/musicality/notation/model/key.rb +137 -0
 - data/lib/musicality/notation/model/keys.rb +37 -0
 - data/lib/musicality/notation/model/link.rb +6 -19
 - data/lib/musicality/notation/model/mark.rb +43 -0
 - data/lib/musicality/notation/model/marks.rb +11 -0
 - data/lib/musicality/notation/model/meter.rb +4 -0
 - data/lib/musicality/notation/model/note.rb +42 -28
 - data/lib/musicality/notation/model/part.rb +18 -5
 - data/lib/musicality/notation/model/pitch.rb +13 -4
 - data/lib/musicality/notation/model/score.rb +104 -66
 - data/lib/musicality/notation/model/symbols.rb +16 -11
 - data/lib/musicality/notation/parsing/articulation_parsing.rb +38 -38
 - data/lib/musicality/notation/parsing/articulation_parsing.treetop +14 -14
 - data/lib/musicality/notation/parsing/link_parsing.rb +6 -6
 - data/lib/musicality/notation/parsing/link_parsing.treetop +3 -3
 - data/lib/musicality/notation/parsing/mark_parsing.rb +138 -0
 - data/lib/musicality/notation/parsing/mark_parsing.treetop +31 -0
 - data/lib/musicality/notation/parsing/note_node.rb +19 -12
 - data/lib/musicality/notation/parsing/note_parsing.rb +218 -87
 - data/lib/musicality/notation/parsing/note_parsing.treetop +9 -5
 - data/lib/musicality/notation/parsing/numbers/nonnegative_integer_parsing.rb +7 -2
 - data/lib/musicality/notation/parsing/numbers/nonnegative_integer_parsing.treetop +1 -1
 - data/lib/musicality/notation/parsing/numbers/positive_integer_parsing.rb +6 -4
 - data/lib/musicality/notation/parsing/numbers/positive_integer_parsing.treetop +1 -1
 - data/lib/musicality/notation/util/function.rb +41 -18
 - data/lib/musicality/packable.rb +156 -0
 - data/lib/musicality/performance/conversion/glissando_converter.rb +2 -2
 - data/lib/musicality/performance/conversion/note_sequence_extractor.rb +223 -70
 - data/lib/musicality/performance/conversion/portamento_converter.rb +5 -2
 - data/lib/musicality/performance/conversion/score_collator.rb +70 -64
 - data/lib/musicality/performance/midi/midi_events.rb +3 -3
 - data/lib/musicality/performance/midi/midi_settings.rb +127 -0
 - data/lib/musicality/performance/midi/midi_util.rb +8 -2
 - data/lib/musicality/performance/midi/part_sequencer.rb +19 -18
 - data/lib/musicality/performance/midi/score_sequencer.rb +13 -9
 - data/lib/musicality/performance/midi/score_sequencing.rb +5 -5
 - data/lib/musicality/performance/model/attack.rb +8 -0
 - data/lib/musicality/performance/model/duration_functions.rb +23 -0
 - data/lib/musicality/performance/model/note_sequence.rb +52 -95
 - data/lib/musicality/performance/model/separation.rb +10 -0
 - data/lib/musicality/performance/supercollider/add_actions.rb +13 -0
 - data/lib/musicality/performance/supercollider/bundle.rb +18 -0
 - data/lib/musicality/performance/supercollider/conductor.rb +125 -0
 - data/lib/musicality/performance/supercollider/group.rb +71 -0
 - data/lib/musicality/performance/supercollider/message.rb +26 -0
 - data/lib/musicality/performance/supercollider/node.rb +122 -0
 - data/lib/musicality/performance/supercollider/performer.rb +123 -0
 - data/lib/musicality/performance/supercollider/score_conducting.rb +17 -0
 - data/lib/musicality/performance/supercollider/server.rb +8 -0
 - data/lib/musicality/performance/supercollider/synth.rb +43 -0
 - data/lib/musicality/performance/supercollider/synthdef.rb +57 -0
 - data/lib/musicality/performance/supercollider/synthdef_settings.rb +23 -0
 - data/lib/musicality/performance/supercollider/synthdefs.rb +1654 -0
 - data/lib/musicality/{composition/model/pitch_class.rb → pitch_class.rb} +1 -1
 - data/lib/musicality/{composition/model/pitch_classes.rb → pitch_classes.rb} +9 -9
 - data/lib/musicality/printing/lilypond/clef.rb +12 -0
 - data/lib/musicality/printing/lilypond/key_engraving.rb +9 -0
 - data/lib/musicality/printing/lilypond/lilypond_settings.rb +105 -0
 - data/lib/musicality/printing/lilypond/meter_engraving.rb +1 -1
 - data/lib/musicality/printing/lilypond/note_engraving.rb +112 -30
 - data/lib/musicality/printing/lilypond/part_engraver.rb +114 -3
 - data/lib/musicality/printing/lilypond/pitch_class_engraving.rb +22 -0
 - data/lib/musicality/printing/lilypond/pitch_engraving.rb +2 -15
 - data/lib/musicality/printing/lilypond/score_engraver.rb +44 -73
 - data/lib/musicality/printing/lilypond/score_engraving.rb +3 -3
 - data/lib/musicality/project/create_tasks.rb +31 -0
 - data/lib/musicality/project/file_cleaner.rb +19 -0
 - data/lib/musicality/project/file_raker.rb +107 -0
 - data/lib/musicality/project/load_config.rb +43 -0
 - data/lib/musicality/project/project.rb +64 -0
 - data/lib/musicality/version.rb +1 -1
 - data/musicality.gemspec +3 -0
 - data/spec/composition/util/random_sampler_spec.rb +1 -1
 - data/spec/notation/conversion/measure_note_map_spec.rb +1 -1
 - data/spec/notation/conversion/note_time_converter_spec.rb +5 -85
 - data/spec/notation/conversion/score_conversion_spec.rb +6 -41
 - data/spec/notation/conversion/score_converter_spec.rb +19 -137
 - data/spec/notation/model/change_spec.rb +55 -0
 - data/spec/notation/model/key_spec.rb +171 -0
 - data/spec/notation/model/link_spec.rb +34 -5
 - data/spec/notation/model/meter_spec.rb +15 -0
 - data/spec/notation/model/note_spec.rb +33 -27
 - data/spec/notation/model/part_spec.rb +53 -4
 - data/spec/notation/model/pitch_spec.rb +15 -0
 - data/spec/notation/model/score_spec.rb +64 -72
 - data/spec/notation/parsing/link_nodes_spec.rb +3 -3
 - data/spec/notation/parsing/link_parsing_spec.rb +6 -6
 - data/spec/notation/parsing/note_node_spec.rb +34 -9
 - data/spec/notation/parsing/note_parsing_spec.rb +11 -9
 - data/spec/notation/parsing/numbers/nonnegative_integer_spec.rb +4 -0
 - data/spec/notation/parsing/pitch_node_spec.rb +0 -1
 - data/spec/notation/util/value_computer_spec.rb +2 -2
 - data/spec/performance/conversion/glissando_converter_spec.rb +9 -9
 - data/spec/performance/conversion/note_sequence_extractor_spec.rb +48 -53
 - data/spec/performance/conversion/portamento_converter_spec.rb +11 -9
 - data/spec/performance/conversion/score_collator_spec.rb +59 -63
 - data/spec/performance/midi/midi_util_spec.rb +22 -8
 - data/spec/performance/midi/part_sequencer_spec.rb +2 -2
 - data/spec/performance/midi/score_sequencer_spec.rb +12 -10
 - data/spec/performance/midi/score_sequencing_spec.rb +2 -2
 - data/spec/performance/model/note_sequence_spec.rb +41 -134
 - data/spec/printing/note_engraving_spec.rb +204 -0
 - data/spec/printing/score_engraver_spec.rb +40 -0
 - data/spec/spec_helper.rb +1 -0
 - metadata +69 -23
 - data/examples/notation/hip.rb +0 -32
 - data/examples/notation/missed_connection.rb +0 -26
 - data/examples/notation/song1.rb +0 -33
 - data/examples/notation/song2.rb +0 -32
 - data/lib/musicality/notation/model/links.rb +0 -11
 - data/lib/musicality/notation/packing/change_packing.rb +0 -56
 - data/lib/musicality/notation/packing/part_packing.rb +0 -31
 - data/lib/musicality/notation/packing/score_packing.rb +0 -123
 - data/lib/musicality/performance/model/note_attacks.rb +0 -19
 - data/lib/musicality/performance/util/note_linker.rb +0 -28
 - data/spec/notation/packing/change_packing_spec.rb +0 -304
 - data/spec/notation/packing/part_packing_spec.rb +0 -66
 - data/spec/notation/packing/score_packing_spec.rb +0 -255
 - data/spec/performance/util/note_linker_spec.rb +0 -68
 
| 
         @@ -1,31 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Musicality
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class Part
         
     | 
| 
       4 
     | 
    
         
            -
              def pack
         
     | 
| 
       5 
     | 
    
         
            -
                packed_notes = notes.map {|n| n.to_s }.join(" ")
         
     | 
| 
       6 
     | 
    
         
            -
                packed_dcs = Hash[ dynamic_changes.map do |offset,change|
         
     | 
| 
       7 
     | 
    
         
            -
                  [ offset, change.pack ]
         
     | 
| 
       8 
     | 
    
         
            -
                end ]
         
     | 
| 
       9 
     | 
    
         
            -
                  
         
     | 
| 
       10 
     | 
    
         
            -
                {
         
     | 
| 
       11 
     | 
    
         
            -
                  'notes' => packed_notes,
         
     | 
| 
       12 
     | 
    
         
            -
                  'start_dynamic' => start_dynamic,
         
     | 
| 
       13 
     | 
    
         
            -
                  'dynamic_changes' => packed_dcs
         
     | 
| 
       14 
     | 
    
         
            -
                }
         
     | 
| 
       15 
     | 
    
         
            -
              end
         
     | 
| 
       16 
     | 
    
         
            -
              
         
     | 
| 
       17 
     | 
    
         
            -
              def self.unpack packing
         
     | 
| 
       18 
     | 
    
         
            -
                unpacked_notes = Note.split_parse(packing["notes"])
         
     | 
| 
       19 
     | 
    
         
            -
                unpacked_dcs = Hash[ packing["dynamic_changes"].map do |offset,change|
         
     | 
| 
       20 
     | 
    
         
            -
                  [ offset,Change.unpack(change) ]
         
     | 
| 
       21 
     | 
    
         
            -
                end ]
         
     | 
| 
       22 
     | 
    
         
            -
                
         
     | 
| 
       23 
     | 
    
         
            -
                new(
         
     | 
| 
       24 
     | 
    
         
            -
                  packing["start_dynamic"],
         
     | 
| 
       25 
     | 
    
         
            -
                  notes: unpacked_notes,
         
     | 
| 
       26 
     | 
    
         
            -
                  dynamic_changes: unpacked_dcs
         
     | 
| 
       27 
     | 
    
         
            -
                )
         
     | 
| 
       28 
     | 
    
         
            -
              end
         
     | 
| 
       29 
     | 
    
         
            -
            end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,123 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Musicality
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class Score
         
     | 
| 
       4 
     | 
    
         
            -
              class Timed < Score
         
     | 
| 
       5 
     | 
    
         
            -
                def pack
         
     | 
| 
       6 
     | 
    
         
            -
                  pack_common
         
     | 
| 
       7 
     | 
    
         
            -
                end
         
     | 
| 
       8 
     | 
    
         
            -
                
         
     | 
| 
       9 
     | 
    
         
            -
                def self.unpack packing
         
     | 
| 
       10 
     | 
    
         
            -
                  new(**Score.unpack_common(packing))
         
     | 
| 
       11 
     | 
    
         
            -
                end
         
     | 
| 
       12 
     | 
    
         
            -
              end
         
     | 
| 
       13 
     | 
    
         
            -
              
         
     | 
| 
       14 
     | 
    
         
            -
              class TempoBased < Score
         
     | 
| 
       15 
     | 
    
         
            -
                def pack
         
     | 
| 
       16 
     | 
    
         
            -
                  pack_common.merge("start_tempo" => @start_tempo,
         
     | 
| 
       17 
     | 
    
         
            -
                    "tempo_changes" => pack_tempo_changes)
         
     | 
| 
       18 
     | 
    
         
            -
                end
         
     | 
| 
       19 
     | 
    
         
            -
                
         
     | 
| 
       20 
     | 
    
         
            -
                def pack_tempo_changes
         
     | 
| 
       21 
     | 
    
         
            -
                  Hash[ tempo_changes.map do |offset,change|
         
     | 
| 
       22 
     | 
    
         
            -
                    [offset,change.pack]
         
     | 
| 
       23 
     | 
    
         
            -
                  end ]
         
     | 
| 
       24 
     | 
    
         
            -
                end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                def self.unpack_tempo_changes packing
         
     | 
| 
       27 
     | 
    
         
            -
                  Hash[ packing["tempo_changes"].map do |k,v|
         
     | 
| 
       28 
     | 
    
         
            -
                    [k, Change.unpack(v) ]
         
     | 
| 
       29 
     | 
    
         
            -
                  end ]
         
     | 
| 
       30 
     | 
    
         
            -
                end
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
                def self.unpack packing
         
     | 
| 
       33 
     | 
    
         
            -
                  unpacked_tcs = Hash[ packing["tempo_changes"].map do |k,v|
         
     | 
| 
       34 
     | 
    
         
            -
                    [k, Change.unpack(v) ]
         
     | 
| 
       35 
     | 
    
         
            -
                  end ]
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
                  Score.unpack_common(packing)
         
     | 
| 
       38 
     | 
    
         
            -
                  new(packing["start_tempo"],
         
     | 
| 
       39 
     | 
    
         
            -
                    tempo_changes: unpacked_tcs,
         
     | 
| 
       40 
     | 
    
         
            -
                    **unpacked)
         
     | 
| 
       41 
     | 
    
         
            -
                end
         
     | 
| 
       42 
     | 
    
         
            -
              end
         
     | 
| 
       43 
     | 
    
         
            -
              
         
     | 
| 
       44 
     | 
    
         
            -
              class Unmeasured < TempoBased
         
     | 
| 
       45 
     | 
    
         
            -
                def self.unpack packing
         
     | 
| 
       46 
     | 
    
         
            -
                  new(packing["start_tempo"],
         
     | 
| 
       47 
     | 
    
         
            -
                    tempo_changes: unpack_tempo_changes(packing),
         
     | 
| 
       48 
     | 
    
         
            -
                    **Score.unpack_common(packing))
         
     | 
| 
       49 
     | 
    
         
            -
                end
         
     | 
| 
       50 
     | 
    
         
            -
              end
         
     | 
| 
       51 
     | 
    
         
            -
              
         
     | 
| 
       52 
     | 
    
         
            -
              class Measured < TempoBased
         
     | 
| 
       53 
     | 
    
         
            -
                def pack
         
     | 
| 
       54 
     | 
    
         
            -
                  return super().merge("start_meter" => pack_start_meter,
         
     | 
| 
       55 
     | 
    
         
            -
                    "meter_changes" => pack_meter_changes)
         
     | 
| 
       56 
     | 
    
         
            -
                end
         
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
                def pack_meter_changes
         
     | 
| 
       59 
     | 
    
         
            -
                  Hash[ meter_changes.map do |off,change|
         
     | 
| 
       60 
     | 
    
         
            -
                    [off,change.pack(:with => :to_s)]
         
     | 
| 
       61 
     | 
    
         
            -
                  end ]
         
     | 
| 
       62 
     | 
    
         
            -
                end
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
                def pack_start_meter
         
     | 
| 
       65 
     | 
    
         
            -
                  start_meter.to_s
         
     | 
| 
       66 
     | 
    
         
            -
                end
         
     | 
| 
       67 
     | 
    
         
            -
                
         
     | 
| 
       68 
     | 
    
         
            -
                def self.unpack_meter_changes packing
         
     | 
| 
       69 
     | 
    
         
            -
                  Hash[ packing["meter_changes"].map do |off,p|
         
     | 
| 
       70 
     | 
    
         
            -
                     [off, Change.unpack(p, :with => :to_meter) ]
         
     | 
| 
       71 
     | 
    
         
            -
                  end ]
         
     | 
| 
       72 
     | 
    
         
            -
                end
         
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
                def self.unpack_start_meter packing
         
     | 
| 
       75 
     | 
    
         
            -
                  Meter.parse(packing["start_meter"])
         
     | 
| 
       76 
     | 
    
         
            -
                end
         
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
                def self.unpack packing
         
     | 
| 
       79 
     | 
    
         
            -
                  new(unpack_start_meter(packing), packing["start_tempo"],
         
     | 
| 
       80 
     | 
    
         
            -
                    tempo_changes: unpack_tempo_changes(packing),
         
     | 
| 
       81 
     | 
    
         
            -
                    meter_changes: unpack_meter_changes(packing),
         
     | 
| 
       82 
     | 
    
         
            -
                    **Score.unpack_common(packing))
         
     | 
| 
       83 
     | 
    
         
            -
                end
         
     | 
| 
       84 
     | 
    
         
            -
              end
         
     | 
| 
       85 
     | 
    
         
            -
              
         
     | 
| 
       86 
     | 
    
         
            -
              def self.unpack packing
         
     | 
| 
       87 
     | 
    
         
            -
                type = const_get(packing["type"])
         
     | 
| 
       88 
     | 
    
         
            -
                type.unpack(packing)
         
     | 
| 
       89 
     | 
    
         
            -
              end
         
     | 
| 
       90 
     | 
    
         
            -
              
         
     | 
| 
       91 
     | 
    
         
            -
              private
         
     | 
| 
       92 
     | 
    
         
            -
              
         
     | 
| 
       93 
     | 
    
         
            -
              def pack_common
         
     | 
| 
       94 
     | 
    
         
            -
                packed_parts = Hash[
         
     | 
| 
       95 
     | 
    
         
            -
                  @parts.map do |name,part|
         
     | 
| 
       96 
     | 
    
         
            -
                    [ name, part.pack ]
         
     | 
| 
       97 
     | 
    
         
            -
                  end
         
     | 
| 
       98 
     | 
    
         
            -
                ]
         
     | 
| 
       99 
     | 
    
         
            -
                packed_prog = @program.map {|seg| seg.to_s }
         
     | 
| 
       100 
     | 
    
         
            -
                
         
     | 
| 
       101 
     | 
    
         
            -
                { "type" => self.class.to_s.split("::")[-1],
         
     | 
| 
       102 
     | 
    
         
            -
                  "program" => packed_prog,
         
     | 
| 
       103 
     | 
    
         
            -
                  "parts" => packed_parts,
         
     | 
| 
       104 
     | 
    
         
            -
                  "title" => @title,
         
     | 
| 
       105 
     | 
    
         
            -
                  "composer" => @composer
         
     | 
| 
       106 
     | 
    
         
            -
                }
         
     | 
| 
       107 
     | 
    
         
            -
              end
         
     | 
| 
       108 
     | 
    
         
            -
              
         
     | 
| 
       109 
     | 
    
         
            -
              def self.unpack_common packing
         
     | 
| 
       110 
     | 
    
         
            -
                unpacked_parts = Hash[ packing["parts"].map do |name,packed|
         
     | 
| 
       111 
     | 
    
         
            -
                  [name, Part.unpack(packed)]
         
     | 
| 
       112 
     | 
    
         
            -
                end ]
         
     | 
| 
       113 
     | 
    
         
            -
                unpacked_prog = packing["program"].map {|str| Segment.parse(str) }
         
     | 
| 
       114 
     | 
    
         
            -
                
         
     | 
| 
       115 
     | 
    
         
            -
                { :program => unpacked_prog,
         
     | 
| 
       116 
     | 
    
         
            -
                  :parts => unpacked_parts,
         
     | 
| 
       117 
     | 
    
         
            -
                  :title => packing["title"],
         
     | 
| 
       118 
     | 
    
         
            -
                  :composer => packing["composer"]
         
     | 
| 
       119 
     | 
    
         
            -
                }
         
     | 
| 
       120 
     | 
    
         
            -
              end    
         
     | 
| 
       121 
     | 
    
         
            -
            end
         
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,19 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Musicality
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            require 'singleton'
         
     | 
| 
       4 
     | 
    
         
            -
            class AccentedAttack
         
     | 
| 
       5 
     | 
    
         
            -
              include Singleton
         
     | 
| 
       6 
     | 
    
         
            -
              
         
     | 
| 
       7 
     | 
    
         
            -
              def accented?; return true; end
         
     | 
| 
       8 
     | 
    
         
            -
            end
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
            class UnaccentedAttack
         
     | 
| 
       11 
     | 
    
         
            -
              include Singleton
         
     | 
| 
       12 
     | 
    
         
            -
              
         
     | 
| 
       13 
     | 
    
         
            -
              def accented?; return false; end
         
     | 
| 
       14 
     | 
    
         
            -
            end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
            ACCENTED = AccentedAttack.instance
         
     | 
| 
       17 
     | 
    
         
            -
            UNACCENTED = UnaccentedAttack.instance
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,28 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module Musicality
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class NoteLinker
         
     | 
| 
       4 
     | 
    
         
            -
              def self.find_unlinked_pitches note
         
     | 
| 
       5 
     | 
    
         
            -
                linked = Set.new(note.pitches) & note.links.keys
         
     | 
| 
       6 
     | 
    
         
            -
                (Set.new(note.pitches) - linked).to_a
         
     | 
| 
       7 
     | 
    
         
            -
              end
         
     | 
| 
       8 
     | 
    
         
            -
              
         
     | 
| 
       9 
     | 
    
         
            -
              def self.find_untargeted_pitches note, next_note
         
     | 
| 
       10 
     | 
    
         
            -
                linked = Set.new(note.pitches) & note.links.keys
         
     | 
| 
       11 
     | 
    
         
            -
                targeted = Set.new(linked.map {|p| note.links[p].target_pitch })
         
     | 
| 
       12 
     | 
    
         
            -
                (Set.new(next_note.pitches) - targeted).to_a
         
     | 
| 
       13 
     | 
    
         
            -
              end
         
     | 
| 
       14 
     | 
    
         
            -
              
         
     | 
| 
       15 
     | 
    
         
            -
              def self.figure_links note, next_note
         
     | 
| 
       16 
     | 
    
         
            -
                unlinked = find_unlinked_pitches(note)
         
     | 
| 
       17 
     | 
    
         
            -
                untargeted = find_untargeted_pitches(note, next_note)
         
     | 
| 
       18 
     | 
    
         
            -
                Optimization.linking(unlinked, untargeted)
         
     | 
| 
       19 
     | 
    
         
            -
              end
         
     | 
| 
       20 
     | 
    
         
            -
              
         
     | 
| 
       21 
     | 
    
         
            -
              def self.fully_link note, next_note, link_class
         
     | 
| 
       22 
     | 
    
         
            -
                figure_links(note,next_note).each do |pitch,tgt_pitch|
         
     | 
| 
       23 
     | 
    
         
            -
                  note.links[pitch] = link_class.new(tgt_pitch)
         
     | 
| 
       24 
     | 
    
         
            -
                end
         
     | 
| 
       25 
     | 
    
         
            -
              end  
         
     | 
| 
       26 
     | 
    
         
            -
            end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,304 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            describe Change::Immediate do
         
     | 
| 
       4 
     | 
    
         
            -
              describe '#pack' do
         
     | 
| 
       5 
     | 
    
         
            -
                before :all do
         
     | 
| 
       6 
     | 
    
         
            -
                  @c = Change::Immediate.new(0.5)
         
     | 
| 
       7 
     | 
    
         
            -
                  @p = @c.pack
         
     | 
| 
       8 
     | 
    
         
            -
                end
         
     | 
| 
       9 
     | 
    
         
            -
                
         
     | 
| 
       10 
     | 
    
         
            -
                it 'should return a Hash' do
         
     | 
| 
       11 
     | 
    
         
            -
                  @p.should be_a Hash
         
     | 
| 
       12 
     | 
    
         
            -
                end
         
     | 
| 
       13 
     | 
    
         
            -
                
         
     | 
| 
       14 
     | 
    
         
            -
                it 'should have "type" and "end_value" keys' do
         
     | 
| 
       15 
     | 
    
         
            -
                  @p.should have_key("type")
         
     | 
| 
       16 
     | 
    
         
            -
                  @p.should have_key("end_value")
         
     | 
| 
       17 
     | 
    
         
            -
                end
         
     | 
| 
       18 
     | 
    
         
            -
                
         
     | 
| 
       19 
     | 
    
         
            -
                it 'should assign "Immediate" to "type" key' do
         
     | 
| 
       20 
     | 
    
         
            -
                  @p["type"].should eq("Immediate")
         
     | 
| 
       21 
     | 
    
         
            -
                end
         
     | 
| 
       22 
     | 
    
         
            -
                
         
     | 
| 
       23 
     | 
    
         
            -
                it 'should assign end_value to "end_value" key' do
         
     | 
| 
       24 
     | 
    
         
            -
                  @p["end_value"].should eq(@c.end_value)
         
     | 
| 
       25 
     | 
    
         
            -
                end
         
     | 
| 
       26 
     | 
    
         
            -
                
         
     | 
| 
       27 
     | 
    
         
            -
                context 'given :with method' do
         
     | 
| 
       28 
     | 
    
         
            -
                  it 'should send the :with method to end_value' do
         
     | 
| 
       29 
     | 
    
         
            -
                    p = @c.pack(:with => :to_s)
         
     | 
| 
       30 
     | 
    
         
            -
                    p["end_value"].should be_a String
         
     | 
| 
       31 
     | 
    
         
            -
                    p["end_value"].to_f.should eq(@c.end_value)
         
     | 
| 
       32 
     | 
    
         
            -
                  end
         
     | 
| 
       33 
     | 
    
         
            -
                end
         
     | 
| 
       34 
     | 
    
         
            -
              end
         
     | 
| 
       35 
     | 
    
         
            -
            end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
            describe Change::Gradual do
         
     | 
| 
       38 
     | 
    
         
            -
              describe '#pack' do
         
     | 
| 
       39 
     | 
    
         
            -
                before :all do
         
     | 
| 
       40 
     | 
    
         
            -
                  @c = Change::Gradual.linear(200,2.5)
         
     | 
| 
       41 
     | 
    
         
            -
                  @p = @c.pack
         
     | 
| 
       42 
     | 
    
         
            -
                end
         
     | 
| 
       43 
     | 
    
         
            -
                
         
     | 
| 
       44 
     | 
    
         
            -
                it 'should return a Hash' do
         
     | 
| 
       45 
     | 
    
         
            -
                  @p.should be_a Hash
         
     | 
| 
       46 
     | 
    
         
            -
                end
         
     | 
| 
       47 
     | 
    
         
            -
                
         
     | 
| 
       48 
     | 
    
         
            -
                it 'should have "type", "end_value", "duration", "transition", and keys' do
         
     | 
| 
       49 
     | 
    
         
            -
                  @p.keys.sort.should eq(["duration","end_value","transition","type"])
         
     | 
| 
       50 
     | 
    
         
            -
                end
         
     | 
| 
       51 
     | 
    
         
            -
                
         
     | 
| 
       52 
     | 
    
         
            -
                it 'should assign "Gradual" to "type" key' do
         
     | 
| 
       53 
     | 
    
         
            -
                  @p["type"].should eq("Gradual")
         
     | 
| 
       54 
     | 
    
         
            -
                end
         
     | 
| 
       55 
     | 
    
         
            -
                
         
     | 
| 
       56 
     | 
    
         
            -
                it 'should assign end_value to "end_value" key' do
         
     | 
| 
       57 
     | 
    
         
            -
                  @p["end_value"].should eq(@c.end_value)
         
     | 
| 
       58 
     | 
    
         
            -
                end
         
     | 
| 
       59 
     | 
    
         
            -
                
         
     | 
| 
       60 
     | 
    
         
            -
                it 'should assign duration to "duration" key' do
         
     | 
| 
       61 
     | 
    
         
            -
                  @p["duration"].should eq(@c.duration)
         
     | 
| 
       62 
     | 
    
         
            -
                end
         
     | 
| 
       63 
     | 
    
         
            -
                
         
     | 
| 
       64 
     | 
    
         
            -
                it 'should assign start value to "start_value" key' do
         
     | 
| 
       65 
     | 
    
         
            -
                  @p["start_value"].should eq(@c.start_value)
         
     | 
| 
       66 
     | 
    
         
            -
                end
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                it 'should assign transition to "transition" key' do
         
     | 
| 
       69 
     | 
    
         
            -
                  @p["transition"].should eq(@c.transition)
         
     | 
| 
       70 
     | 
    
         
            -
                end
         
     | 
| 
       71 
     | 
    
         
            -
                
         
     | 
| 
       72 
     | 
    
         
            -
                context 'given :with method' do
         
     | 
| 
       73 
     | 
    
         
            -
                  it 'should send the :with method to end_value' do
         
     | 
| 
       74 
     | 
    
         
            -
                    p = @c.pack(:with => :to_s)
         
     | 
| 
       75 
     | 
    
         
            -
                    p["end_value"].should be_a String
         
     | 
| 
       76 
     | 
    
         
            -
                    p["end_value"].to_f.should eq(@c.end_value)
         
     | 
| 
       77 
     | 
    
         
            -
                  end
         
     | 
| 
       78 
     | 
    
         
            -
                end
         
     | 
| 
       79 
     | 
    
         
            -
                
         
     | 
| 
       80 
     | 
    
         
            -
                context 'given start value' do
         
     | 
| 
       81 
     | 
    
         
            -
                  it 'should assign start_value to "start_value" ' do
         
     | 
| 
       82 
     | 
    
         
            -
                    c = Change::Gradual.linear(200,2.5,start_value: 20)
         
     | 
| 
       83 
     | 
    
         
            -
                    p = c.pack
         
     | 
| 
       84 
     | 
    
         
            -
                    p.should have_key("start_value")
         
     | 
| 
       85 
     | 
    
         
            -
                    p["start_value"].should eq(c.start_value)
         
     | 
| 
       86 
     | 
    
         
            -
                  end
         
     | 
| 
       87 
     | 
    
         
            -
                  
         
     | 
| 
       88 
     | 
    
         
            -
                  context 'given :with method' do
         
     | 
| 
       89 
     | 
    
         
            -
                    it 'should send the :with method to end_value' do
         
     | 
| 
       90 
     | 
    
         
            -
                      c = Change::Gradual.linear(200,2.5,start_value: 20)
         
     | 
| 
       91 
     | 
    
         
            -
                      p = c.pack(:with => :to_s)
         
     | 
| 
       92 
     | 
    
         
            -
                      p["start_value"].should be_a String
         
     | 
| 
       93 
     | 
    
         
            -
                      p["start_value"].to_f.should eq(c.start_value)
         
     | 
| 
       94 
     | 
    
         
            -
                    end
         
     | 
| 
       95 
     | 
    
         
            -
                  end
         
     | 
| 
       96 
     | 
    
         
            -
                end
         
     | 
| 
       97 
     | 
    
         
            -
              end
         
     | 
| 
       98 
     | 
    
         
            -
            end
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
            describe Change::Gradual::Trimmed do
         
     | 
| 
       101 
     | 
    
         
            -
              describe '#pack' do
         
     | 
| 
       102 
     | 
    
         
            -
                before :all do
         
     | 
| 
       103 
     | 
    
         
            -
                  @c = Change::Gradual::Trimmed.linear(200,2.5,preceding:1,remaining:0.5)
         
     | 
| 
       104 
     | 
    
         
            -
                  @p = @c.pack
         
     | 
| 
       105 
     | 
    
         
            -
                end
         
     | 
| 
       106 
     | 
    
         
            -
                
         
     | 
| 
       107 
     | 
    
         
            -
                it 'should return a Hash' do
         
     | 
| 
       108 
     | 
    
         
            -
                  @p.should be_a Hash
         
     | 
| 
       109 
     | 
    
         
            -
                end
         
     | 
| 
       110 
     | 
    
         
            -
                
         
     | 
| 
       111 
     | 
    
         
            -
                it 'should have "type", "end_value", "duration", "transition", "preceding", "remaining" keys' do
         
     | 
| 
       112 
     | 
    
         
            -
                  @p.keys.sort.should eq(["duration","end_value","preceding","remaining","transition","type"])
         
     | 
| 
       113 
     | 
    
         
            -
                end
         
     | 
| 
       114 
     | 
    
         
            -
                
         
     | 
| 
       115 
     | 
    
         
            -
                it 'should assign "Gradual::Trimmed" to "type" key' do
         
     | 
| 
       116 
     | 
    
         
            -
                  @p["type"].should eq("Gradual::Trimmed")
         
     | 
| 
       117 
     | 
    
         
            -
                end
         
     | 
| 
       118 
     | 
    
         
            -
                
         
     | 
| 
       119 
     | 
    
         
            -
                it 'should assign end_value to "end_value" key' do
         
     | 
| 
       120 
     | 
    
         
            -
                  @p["end_value"].should eq(@c.end_value)
         
     | 
| 
       121 
     | 
    
         
            -
                end
         
     | 
| 
       122 
     | 
    
         
            -
                
         
     | 
| 
       123 
     | 
    
         
            -
                it 'should assign duration to "duration" key' do
         
     | 
| 
       124 
     | 
    
         
            -
                  @p["duration"].should eq(@c.duration)
         
     | 
| 
       125 
     | 
    
         
            -
                end
         
     | 
| 
       126 
     | 
    
         
            -
                
         
     | 
| 
       127 
     | 
    
         
            -
                it 'should assign transition to "transition" key' do
         
     | 
| 
       128 
     | 
    
         
            -
                  @p["transition"].should eq(@c.transition)
         
     | 
| 
       129 
     | 
    
         
            -
                end
         
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
                it 'should assign preceding to "preceding" key' do
         
     | 
| 
       132 
     | 
    
         
            -
                  @p["preceding"].should eq(@c.preceding)
         
     | 
| 
       133 
     | 
    
         
            -
                end
         
     | 
| 
       134 
     | 
    
         
            -
                
         
     | 
| 
       135 
     | 
    
         
            -
                it 'should assign remaining to "remaining" key' do
         
     | 
| 
       136 
     | 
    
         
            -
                  @p["remaining"].should eq(@c.remaining)
         
     | 
| 
       137 
     | 
    
         
            -
                end
         
     | 
| 
       138 
     | 
    
         
            -
                
         
     | 
| 
       139 
     | 
    
         
            -
                context 'given :with method' do
         
     | 
| 
       140 
     | 
    
         
            -
                  it 'should send the :with method to end_value' do
         
     | 
| 
       141 
     | 
    
         
            -
                    p = @c.pack(:with => :to_s)
         
     | 
| 
       142 
     | 
    
         
            -
                    p["end_value"].should be_a String
         
     | 
| 
       143 
     | 
    
         
            -
                    p["end_value"].to_f.should eq(@c.end_value)
         
     | 
| 
       144 
     | 
    
         
            -
                  end
         
     | 
| 
       145 
     | 
    
         
            -
                end
         
     | 
| 
       146 
     | 
    
         
            -
                
         
     | 
| 
       147 
     | 
    
         
            -
                context 'given start value' do
         
     | 
| 
       148 
     | 
    
         
            -
                  it 'should assign start_value to "start_value" ' do
         
     | 
| 
       149 
     | 
    
         
            -
                    c = Change::Gradual.linear(200,2.5,start_value: 20).trim(0.5,0.5)
         
     | 
| 
       150 
     | 
    
         
            -
                    p = c.pack
         
     | 
| 
       151 
     | 
    
         
            -
                    p.should have_key("start_value")
         
     | 
| 
       152 
     | 
    
         
            -
                    p["start_value"].should eq(c.start_value)
         
     | 
| 
       153 
     | 
    
         
            -
                  end
         
     | 
| 
       154 
     | 
    
         
            -
                  
         
     | 
| 
       155 
     | 
    
         
            -
                  context 'given :with method' do
         
     | 
| 
       156 
     | 
    
         
            -
                  it 'should send the :with method to end_value' do
         
     | 
| 
       157 
     | 
    
         
            -
                    c = Change::Gradual.linear(200,2.5,start_value: 20).trim(0.5,0.5)
         
     | 
| 
       158 
     | 
    
         
            -
                    p = c.pack(:with => :to_s)
         
     | 
| 
       159 
     | 
    
         
            -
                    p["start_value"].should be_a String
         
     | 
| 
       160 
     | 
    
         
            -
                    p["start_value"].to_f.should eq(c.start_value)
         
     | 
| 
       161 
     | 
    
         
            -
                    end
         
     | 
| 
       162 
     | 
    
         
            -
                  end
         
     | 
| 
       163 
     | 
    
         
            -
                end
         
     | 
| 
       164 
     | 
    
         
            -
              end
         
     | 
| 
       165 
     | 
    
         
            -
            end
         
     | 
| 
       166 
     | 
    
         
            -
             
     | 
| 
       167 
     | 
    
         
            -
            describe Change do
         
     | 
| 
       168 
     | 
    
         
            -
              describe '.unpack' do
         
     | 
| 
       169 
     | 
    
         
            -
                context 'given a packed immediate change' do
         
     | 
| 
       170 
     | 
    
         
            -
                  before :all do
         
     | 
| 
       171 
     | 
    
         
            -
                    @c = Change::Immediate.new(0.5)
         
     | 
| 
       172 
     | 
    
         
            -
                    @a = @c.pack
         
     | 
| 
       173 
     | 
    
         
            -
                    @c2 = Change.unpack(@a)
         
     | 
| 
       174 
     | 
    
         
            -
                  end
         
     | 
| 
       175 
     | 
    
         
            -
                  
         
     | 
| 
       176 
     | 
    
         
            -
                  it 'should return a Change::Immediate' do
         
     | 
| 
       177 
     | 
    
         
            -
                    @c2.should be_a Change::Immediate
         
     | 
| 
       178 
     | 
    
         
            -
                  end
         
     | 
| 
       179 
     | 
    
         
            -
                  
         
     | 
| 
       180 
     | 
    
         
            -
                  it 'should successfully unpack the change end_value' do
         
     | 
| 
       181 
     | 
    
         
            -
                    @c2.end_value.should eq @c.end_value
         
     | 
| 
       182 
     | 
    
         
            -
                  end
         
     | 
| 
       183 
     | 
    
         
            -
                  
         
     | 
| 
       184 
     | 
    
         
            -
                  context 'pack/unpack using :with method' do
         
     | 
| 
       185 
     | 
    
         
            -
                    it 'should use given :with method to convert end_value' do
         
     | 
| 
       186 
     | 
    
         
            -
                      c = Change::Immediate.new(0.5)
         
     | 
| 
       187 
     | 
    
         
            -
                      h = c.pack(:with => :to_s)
         
     | 
| 
       188 
     | 
    
         
            -
                      c2 = Change.unpack(h)
         
     | 
| 
       189 
     | 
    
         
            -
                      c2.end_value.should be_a String
         
     | 
| 
       190 
     | 
    
         
            -
                      c3 = Change.unpack(h, :with => :to_f)
         
     | 
| 
       191 
     | 
    
         
            -
                      c3.end_value.should be_a Float
         
     | 
| 
       192 
     | 
    
         
            -
                    end
         
     | 
| 
       193 
     | 
    
         
            -
                  end
         
     | 
| 
       194 
     | 
    
         
            -
                end
         
     | 
| 
       195 
     | 
    
         
            -
                
         
     | 
| 
       196 
     | 
    
         
            -
                context 'given a packed gradual change' do
         
     | 
| 
       197 
     | 
    
         
            -
                  before :all do
         
     | 
| 
       198 
     | 
    
         
            -
                    @c = Change::Gradual.sigmoid(0.3,1.5)
         
     | 
| 
       199 
     | 
    
         
            -
                    @a = @c.pack
         
     | 
| 
       200 
     | 
    
         
            -
                    @c2 = Change.unpack(@a)
         
     | 
| 
       201 
     | 
    
         
            -
                  end
         
     | 
| 
       202 
     | 
    
         
            -
                  
         
     | 
| 
       203 
     | 
    
         
            -
                  it 'should return a Change::Gradual' do
         
     | 
| 
       204 
     | 
    
         
            -
                    @c2.should be_a Change::Gradual
         
     | 
| 
       205 
     | 
    
         
            -
                  end
         
     | 
| 
       206 
     | 
    
         
            -
                  
         
     | 
| 
       207 
     | 
    
         
            -
                  it 'should unpack the end_value' do
         
     | 
| 
       208 
     | 
    
         
            -
                    @c2.end_value.should eq @c.end_value
         
     | 
| 
       209 
     | 
    
         
            -
                  end
         
     | 
| 
       210 
     | 
    
         
            -
                  
         
     | 
| 
       211 
     | 
    
         
            -
                  it 'should unpack the change duration' do
         
     | 
| 
       212 
     | 
    
         
            -
                    @c2.duration.should eq @c.duration
         
     | 
| 
       213 
     | 
    
         
            -
                  end
         
     | 
| 
       214 
     | 
    
         
            -
             
     | 
| 
       215 
     | 
    
         
            -
                  it 'should unpack the change transition' do
         
     | 
| 
       216 
     | 
    
         
            -
                    @c2.transition.should eq @c.transition
         
     | 
| 
       217 
     | 
    
         
            -
                  end
         
     | 
| 
       218 
     | 
    
         
            -
                  
         
     | 
| 
       219 
     | 
    
         
            -
                  it 'should unpack the change start_value' do
         
     | 
| 
       220 
     | 
    
         
            -
                    @c2.start_value.should eq @c.start_value
         
     | 
| 
       221 
     | 
    
         
            -
                  end
         
     | 
| 
       222 
     | 
    
         
            -
                  
         
     | 
| 
       223 
     | 
    
         
            -
                  context 'pack/unpack using :with method' do
         
     | 
| 
       224 
     | 
    
         
            -
                    it 'should use given :with method to convert end_value' do
         
     | 
| 
       225 
     | 
    
         
            -
                      c = Change::Gradual.linear(0.5,2)
         
     | 
| 
       226 
     | 
    
         
            -
                      h = c.pack(:with => :to_s)
         
     | 
| 
       227 
     | 
    
         
            -
                      c2 = Change.unpack(h)
         
     | 
| 
       228 
     | 
    
         
            -
                      c2.end_value.should be_a String
         
     | 
| 
       229 
     | 
    
         
            -
                      c3 = Change.unpack(h, :with => :to_f)
         
     | 
| 
       230 
     | 
    
         
            -
                      c3.end_value.should be_a Float
         
     | 
| 
       231 
     | 
    
         
            -
                    end
         
     | 
| 
       232 
     | 
    
         
            -
                    
         
     | 
| 
       233 
     | 
    
         
            -
                    context 'when change start_value is not nil' do
         
     | 
| 
       234 
     | 
    
         
            -
                      it 'should use given :with method to convert start_value' do
         
     | 
| 
       235 
     | 
    
         
            -
                        c = Change::Gradual.linear(0.5,2,start_value: 0.1)
         
     | 
| 
       236 
     | 
    
         
            -
                        h = c.pack(:with => :to_s)
         
     | 
| 
       237 
     | 
    
         
            -
                        c2 = Change.unpack(h)
         
     | 
| 
       238 
     | 
    
         
            -
                        c2.start_value.should be_a String
         
     | 
| 
       239 
     | 
    
         
            -
                        c3 = Change.unpack(h, :with => :to_f)
         
     | 
| 
       240 
     | 
    
         
            -
                        c3.start_value.should be_a Float
         
     | 
| 
       241 
     | 
    
         
            -
                      end
         
     | 
| 
       242 
     | 
    
         
            -
                    end
         
     | 
| 
       243 
     | 
    
         
            -
                  end
         
     | 
| 
       244 
     | 
    
         
            -
                end
         
     | 
| 
       245 
     | 
    
         
            -
                
         
     | 
| 
       246 
     | 
    
         
            -
                context 'given a packed gradual (trimmed) change' do
         
     | 
| 
       247 
     | 
    
         
            -
                  before :all do
         
     | 
| 
       248 
     | 
    
         
            -
                    @c = Change::Gradual::Trimmed.sigmoid(0.3,1.5,preceding:0.1,remaining:0.1)
         
     | 
| 
       249 
     | 
    
         
            -
                    @a = @c.pack
         
     | 
| 
       250 
     | 
    
         
            -
                    @c2 = Change.unpack(@a)
         
     | 
| 
       251 
     | 
    
         
            -
                  end
         
     | 
| 
       252 
     | 
    
         
            -
                  
         
     | 
| 
       253 
     | 
    
         
            -
                  it 'should return a Change::Gradual' do
         
     | 
| 
       254 
     | 
    
         
            -
                    @c2.should be_a Change::Gradual
         
     | 
| 
       255 
     | 
    
         
            -
                  end
         
     | 
| 
       256 
     | 
    
         
            -
                  
         
     | 
| 
       257 
     | 
    
         
            -
                  it 'should successfully unpack the end_value' do
         
     | 
| 
       258 
     | 
    
         
            -
                    @c2.end_value.should eq @c.end_value
         
     | 
| 
       259 
     | 
    
         
            -
                  end
         
     | 
| 
       260 
     | 
    
         
            -
                  
         
     | 
| 
       261 
     | 
    
         
            -
                  it 'should successfully unpack the change duration' do
         
     | 
| 
       262 
     | 
    
         
            -
                    @c2.duration.should eq @c.duration
         
     | 
| 
       263 
     | 
    
         
            -
                  end
         
     | 
| 
       264 
     | 
    
         
            -
             
     | 
| 
       265 
     | 
    
         
            -
                  it 'should successfully unpack the change transition' do
         
     | 
| 
       266 
     | 
    
         
            -
                    @c2.transition.should eq @c.transition
         
     | 
| 
       267 
     | 
    
         
            -
                  end
         
     | 
| 
       268 
     | 
    
         
            -
                  
         
     | 
| 
       269 
     | 
    
         
            -
                  it 'should unpack the change start_value' do
         
     | 
| 
       270 
     | 
    
         
            -
                    @c2.start_value.should eq @c.start_value
         
     | 
| 
       271 
     | 
    
         
            -
                  end
         
     | 
| 
       272 
     | 
    
         
            -
                  
         
     | 
| 
       273 
     | 
    
         
            -
                  it 'should successfully unpack the change preceding' do
         
     | 
| 
       274 
     | 
    
         
            -
                    @c2.preceding.should eq @c.preceding
         
     | 
| 
       275 
     | 
    
         
            -
                  end
         
     | 
| 
       276 
     | 
    
         
            -
                  
         
     | 
| 
       277 
     | 
    
         
            -
                  it 'should successfully unpack the change remaining' do
         
     | 
| 
       278 
     | 
    
         
            -
                    @c2.remaining.should eq @c.remaining
         
     | 
| 
       279 
     | 
    
         
            -
                  end
         
     | 
| 
       280 
     | 
    
         
            -
                  
         
     | 
| 
       281 
     | 
    
         
            -
                  context 'pack/unpack using :with method' do
         
     | 
| 
       282 
     | 
    
         
            -
                    it 'should use given :with method to convert end_value' do
         
     | 
| 
       283 
     | 
    
         
            -
                      c = Change::Gradual.linear(0.5,2).trim(0.4,0.3)
         
     | 
| 
       284 
     | 
    
         
            -
                      h = c.pack(:with => :to_s)
         
     | 
| 
       285 
     | 
    
         
            -
                      c2 = Change.unpack(h)
         
     | 
| 
       286 
     | 
    
         
            -
                      c2.end_value.should be_a String
         
     | 
| 
       287 
     | 
    
         
            -
                      c3 = Change.unpack(h, :with => :to_f)
         
     | 
| 
       288 
     | 
    
         
            -
                      c3.end_value.should be_a Float
         
     | 
| 
       289 
     | 
    
         
            -
                    end
         
     | 
| 
       290 
     | 
    
         
            -
                    
         
     | 
| 
       291 
     | 
    
         
            -
                    context 'when change start_value is not nil' do
         
     | 
| 
       292 
     | 
    
         
            -
                      it 'should use given :with method to convert start_value' do
         
     | 
| 
       293 
     | 
    
         
            -
                        c = Change::Gradual.linear(0.5,2,start_value: 0.1).trim(0.4,0.3)
         
     | 
| 
       294 
     | 
    
         
            -
                        h = c.pack(:with => :to_s)
         
     | 
| 
       295 
     | 
    
         
            -
                        c2 = Change.unpack(h)
         
     | 
| 
       296 
     | 
    
         
            -
                        c2.start_value.should be_a String
         
     | 
| 
       297 
     | 
    
         
            -
                        c3 = Change.unpack(h, :with => :to_f)
         
     | 
| 
       298 
     | 
    
         
            -
                        c3.start_value.should be_a Float
         
     | 
| 
       299 
     | 
    
         
            -
                      end
         
     | 
| 
       300 
     | 
    
         
            -
                    end
         
     | 
| 
       301 
     | 
    
         
            -
                  end
         
     | 
| 
       302 
     | 
    
         
            -
                end    
         
     | 
| 
       303 
     | 
    
         
            -
              end
         
     | 
| 
       304 
     | 
    
         
            -
            end
         
     |