Class: MusicSetTheory::Temperament::SeqDict

Inherits:
Object
  • Object
show all
Defined in:
lib/music_set_theory/temperament.rb,
lib/music_set_theory/temperament.rb,
lib/music_set_theory/temperament.rb

Overview

The seq_dict class acts as a dictionary for noteseq instances. It allows users and programmers to look up noteseqs by name, by abbreviation, and by the sequence of integers representing the positions in the sequence. Each seq_dict should be assigned to one dictionary.

Defined Under Namespace

Classes: NseqtypeInsDict

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nseq_types, nseq_temp) ⇒ SeqDict

The constructor for seq_dict.

Args

nseq_types

a list of possible nseq_type values for lookups.

nseq_temp

the associated temperament object.



246
247
248
249
250
251
252
# File 'lib/music_set_theory/temperament.rb', line 246

def initialize( nseq_types, nseq_temp )
  self.nseq_temp     = nseq_temp;
  self.nseqtype_maps = {};
  for i in nseq_types
    self.nseqtype_maps[i] = NseqtypeInsDict.new(i);
  end
end

Instance Attribute Details

#nseq_tempObject

Returns the value of attribute nseq_temp.



238
239
240
# File 'lib/music_set_theory/temperament.rb', line 238

def nseq_temp
  @nseq_temp
end

#nseqtype_mapsObject

Returns the value of attribute nseqtype_maps.



239
240
241
# File 'lib/music_set_theory/temperament.rb', line 239

def nseqtype_maps
  @nseqtype_maps
end

Instance Method Details

#add_elem(elem, nseq_type, name_s, abbrv_s, seqpos) ⇒ Object

This adds an element to seq_dict.

Args

elem

the element to add to seq_dict instance.

nseq_type

the type of the elemenet (such as scale or chord).

name_s

a string, or a sequence of strings. This provides names as keys that map onto elem.

abbrv_s

a string, or a sequence of strings. This provides abbreviations as keys that map onto elem.

seqpos

a sequence. A tuple form will be used as a key that maps onto elem.

Desc

If nseq_type is not associated with any of the sub-dictionaries in seq_dict, then this function exits.



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/music_set_theory/temperament.rb', line 281

def add_elem( elem, nseq_type, name_s, abbrv_s, seqpos )

  #
  if !(self.nseqtype_maps.include? nseq_type)
    return false
  end

  #
  sub_dictionary = self.nseqtype_maps[nseq_type]

  #
  ourmod = self.nseq_temp.no_keys
  ourtuple = seqpos.map{|i| i % ourmod }.sort.freeze
  sub_dictionary.seqpos_dict[ourtuple] = elem

  #
  if name_s.is_a? String
    sub_dictionary.name_dict[name_s] = elem
  else
    for s in name_s
      sub_dictionary.name_dict[s] = elem
    end
  end

  # if isinstance(abbrv_s, str)
  if abbrv_s.is_a? String
    sub_dictionary.abbrv_dict[abbrv_s] = elem
  else
    for s in abbrv_s
      sub_dictionary.abbrv_dict[s] = elem
    end
  end

  true
end

#check_nseqby_abbrv(nseq_type, abbrv) ⇒ Object

Checks if there is a noteseq with a given abbreviation.



330
331
332
333
# File 'lib/music_set_theory/temperament.rb', line 330

def check_nseqby_abbrv( nseq_type, abbrv )
  # return abbrv in self.nseqtype_maps[nseq_type].abbrv_dict
  self.nseqtype_maps[nseq_type].abbrv_dict.key?(abbrv)
end

#check_nseqby_name(nseq_type, name) ⇒ Object

Checks if there is a noteseq with a given name.



324
325
326
327
# File 'lib/music_set_theory/temperament.rb', line 324

def check_nseqby_name( nseq_type, name )
  # return name in self.nseqtype_maps[nseq_type].name_dict;
  self.nseqtype_maps[nseq_type].name_dict.key?(name)
end

#check_nseqby_seqpos(nseq_type, seqpos) ⇒ Object

Checks if there is a noteseq with a given sequence position.



336
337
338
339
340
341
# File 'lib/music_set_theory/temperament.rb', line 336

def check_nseqby_seqpos( nseq_type, seqpos )
  # sortedseqpos = tuple(sorted(seqpos))
  # return sortedseqpos in self.nseqtype_maps[nseq_type].seqpos_dict
  sortedseqpos = seqpos.sort.freeze
  self.nseqtype_maps[nseq_type].seqpos_dict.key?(sortedseqpos)
end

#check_nseqby_subdict(nseq_type) ⇒ Object

Checks if there is a subdictionary associated with nseq_type.



318
319
320
321
# File 'lib/music_set_theory/temperament.rb', line 318

def check_nseqby_subdict( nseq_type )
  #return nseq_type in self.nseqtype_maps
  self.nseqtype_maps.key?(nseq_type)
end

#get_nseqby_abbrv(abbrv, nseq_type) ⇒ Object

Looks up a noteseq by abbreviation.



353
354
355
356
# File 'lib/music_set_theory/temperament.rb', line 353

def get_nseqby_abbrv( abbrv, nseq_type )
  # return self.nseqtype_maps[nseq_type].abbrv_dict[abbrv]
  self.nseqtype_maps[nseq_type].abbrv_dict[abbrv]
end

#get_nseqby_name(name, nseq_type) ⇒ Object

Looks up a noteseq by name.



347
348
349
350
# File 'lib/music_set_theory/temperament.rb', line 347

def get_nseqby_name( name, nseq_type )
  # return self.nseqtype_maps[nseq_type].name_dict[name]
  self.nseqtype_maps[nseq_type].name_dict[name]
end

#get_nseqby_seqpos(seqpos, nseq_type) ⇒ Object

Looks up a noteseq by sequence position.



359
360
361
362
363
364
# File 'lib/music_set_theory/temperament.rb', line 359

def get_nseqby_seqpos( seqpos, nseq_type )
  # sortedseqpos = tuple(sorted(seqpos))
  # return self.nseqtype_maps[nseq_type].seqpos_dict[sortedseqpos]
  sortedseqpos = seqpos.sort.freeze
  self.nseqtype_maps[nseq_type].seqpos_dict[sortedseqpos]
end