Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
3.7KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #include "mapping.H"
  19. #include "stdlib.h"
  20. #include "common.h"
  21. /* Is C++'s dispatching useless or what? */
  22. #define IS_INSTRUMENT ( _type == INSTRUMENT )
  23. Mapping::Mapping ( )
  24. {
  25. _key = 0;
  26. _type = NONE;
  27. }
  28. bool
  29. Mapping::open ( enum map_type type, const char *name )
  30. {
  31. switch ( type )
  32. {
  33. case INSTRUMENT:
  34. _instrument = Instrument::open( name );
  35. break;
  36. case SCALE:
  37. _scale = Scale::open( name );
  38. break;
  39. default:
  40. ASSERTION( "invalid mapping type ");
  41. break;
  42. }
  43. if ( ! _scale )
  44. return false;
  45. _type = type;
  46. return true;
  47. }
  48. Mapping::Mapping ( const Mapping &rhs )
  49. {
  50. _key = rhs._key;
  51. _type = rhs._type;
  52. _instrument = rhs._instrument;
  53. }
  54. const char *
  55. Mapping::name ( void ) const
  56. {
  57. switch ( _type )
  58. {
  59. case INSTRUMENT:
  60. return _instrument->name();
  61. case SCALE:
  62. return _scale->name();
  63. }
  64. return NULL;
  65. }
  66. int
  67. Mapping::height ( void ) const
  68. {
  69. if ( IS_INSTRUMENT )
  70. return _instrument->height();
  71. else
  72. return 0;
  73. }
  74. void
  75. Mapping::key ( int n )
  76. {
  77. if ( n > 11 || n < 0 )
  78. ASSERTION( "key selection out of range: %d", n );
  79. _key = n;
  80. }
  81. int
  82. Mapping::key ( void ) const
  83. {
  84. return _type == INSTRUMENT ? -1 : _key;
  85. }
  86. void
  87. Mapping::translate ( midievent *e ) const
  88. {
  89. switch ( _type )
  90. {
  91. case INSTRUMENT:
  92. return _instrument->translate( e );
  93. case SCALE:
  94. return _scale->translate( _key, e );
  95. }
  96. }
  97. int
  98. Mapping::velocity ( int n ) const
  99. {
  100. switch ( _type )
  101. {
  102. case INSTRUMENT:
  103. return _instrument->velocity( n );
  104. case SCALE:
  105. return 0;
  106. }
  107. return 0;
  108. }
  109. const char *
  110. Mapping::note_name ( int n ) const
  111. {
  112. switch ( _type )
  113. {
  114. case INSTRUMENT:
  115. return _instrument->note_name( n );
  116. case SCALE:
  117. return _scale->note_name( _key, n );
  118. }
  119. return NULL;
  120. }
  121. /* For the instrument editor... */
  122. Instrument *
  123. Mapping::instrument ( void ) const
  124. {
  125. if ( IS_INSTRUMENT )
  126. return _instrument;
  127. else
  128. return NULL;
  129. }
  130. /** return a string describing the type of this mapping */
  131. const char *
  132. Mapping::type ( void ) const
  133. {
  134. return IS_INSTRUMENT ? "Instrument" : "Scale";
  135. }
  136. bool
  137. Mapping::editable ( void ) const
  138. {
  139. return IS_INSTRUMENT ? true : false;
  140. }