Skip to content

Commit

Permalink
Support loading IFF and raw samples with no extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
martincameron committed Jun 3, 2020
1 parent 6840f05 commit 7f4b2fe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A simple music editor for 4 and 8 channel Protracker modules.

Modules and samples can be loaded by pressing DIR and navigating to the file.

Samples must have the file extension ".WAV" ".IFF" or ".RAW".
Hold shift to load IFF-8SVX and signed 8-bit RAW samples with no file extension.

Notes can be entered using a virtual piano keyboard (QWERTY layout).

Expand Down
63 changes: 34 additions & 29 deletions Tracker3.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,10 @@ public synchronized void keyPressed( KeyEvent e )
switch( gadType[ focus ] )
{
case GAD_TYPE_TEXTBOX:
keyTextbox( focus, e.getKeyChar(), e.getKeyCode() );
keyTextbox( focus, e.getKeyChar(), e.getKeyCode(), e.isShiftDown() );
break;
case GAD_TYPE_LISTBOX:
keyListbox( focus, e.getKeyChar(), e.getKeyCode() );
keyListbox( focus, e.getKeyChar(), e.getKeyCode(), e.isShiftDown() );
trigger( -1, mapEventKey( KEY_MAP, e.getKeyCode() ) );
break;
case GAD_TYPE_PATTERN:
Expand Down Expand Up @@ -460,18 +460,18 @@ public synchronized void mousePressed( MouseEvent e )
clickTextbox( clicked );
break;
case GAD_TYPE_SLIDER:
clickSlider( clicked );
clickSlider( clicked, e.isShiftDown() );
break;
case GAD_TYPE_LISTBOX:
clickListbox( clicked );
clickListbox( clicked, e.isShiftDown() );
break;
case GAD_TYPE_PATTERN:
clickPattern( clicked, e.isShiftDown() );
break;
default:
if( clicked > 0 )
{
action( clicked );
action( clicked, e.isShiftDown() );
}
}
focus = clicked;
Expand All @@ -489,13 +489,13 @@ public synchronized void mouseReleased( MouseEvent e )
{
gadSelected[ focus ] = false;
gadRedraw[ focus ] = true;
action( focus );
action( focus, e.isShiftDown() );
focus = 0;
repaint();
}
break;
case GAD_TYPE_SLIDER:
action( focus );
action( focus, e.isShiftDown() );
focus = 0;
repaint();
break;
Expand Down Expand Up @@ -853,7 +853,7 @@ private void clickTextbox( int gadnum )
gadRedraw[ gadnum ] = true;
}

private void keyTextbox( int gadnum, char chr, int key )
private void keyTextbox( int gadnum, char chr, int key, boolean shift )
{
int columns = ( gadWidth[ gadnum ] - 16 ) / 8;
String text = gadText[ gadnum ][ 0 ];
Expand Down Expand Up @@ -924,7 +924,7 @@ private void keyTextbox( int gadnum, char chr, int key )
default:
if( chr == 10 )
{
action( gadnum );
action( gadnum, shift );
text = gadText[ gadnum ][ 0 ];
focus = 0;
}
Expand Down Expand Up @@ -962,7 +962,7 @@ private void drawSlider( Graphics g, int gadnum )
raiseBox( g, x + 2, y + d + 2, w - 4, s );
}

private void clickSlider( int gadnum )
private void clickSlider( int gadnum, boolean shift )
{
int ss = ( gadHeight[ gadnum ] - 12 ) * gadRange[ gadnum ] / gadMax[ gadnum ] + 8;
int so = ( gadHeight[ gadnum ] - 12 ) * gadValue[ gadnum ] / gadMax[ gadnum ];
Expand All @@ -976,7 +976,7 @@ private void clickSlider( int gadnum )
}
gadValue[ gadnum ] = sp;
gadRedraw[ gadLink[ gadnum ] > 0 ? gadLink[ gadnum ] : gadnum ] = true;
action( gadnum );
action( gadnum, shift );
}
else if( clickY > ( sy + ss ) )
{
Expand All @@ -987,7 +987,7 @@ else if( clickY > ( sy + ss ) )
}
gadValue[ gadnum ] = sp;
gadRedraw[ gadLink[ gadnum ] > 0 ? gadLink[ gadnum ] : gadnum ] = true;
action( gadnum );
action( gadnum, shift );
}
}

Expand Down Expand Up @@ -1070,14 +1070,14 @@ else if( gadValues[ gadnum ] != null && idx < gadValues[ gadnum ].length )
}
}

private void clickListbox( int gadnum )
private void clickListbox( int gadnum, boolean shift )
{
int time = ( int ) System.currentTimeMillis();
int dt = time - gadRange[ gadnum ];
int item = gadValue[ gadnum ] + ( clickY - gadY[ gadnum ] - 6 ) / 16;
if( item == gadItem[ gadnum ] && dt > 0 && dt < 500 )
{
action( gadnum );
action( gadnum, shift );
gadRange[ gadnum ] = 0;
}
else
Expand All @@ -1091,7 +1091,7 @@ private void clickListbox( int gadnum )
}
}

private void keyListbox( int gadnum, char chr, int key )
private void keyListbox( int gadnum, char chr, int key, boolean shift )
{
int item = gadItem[ gadnum ];
switch( key )
Expand Down Expand Up @@ -1124,7 +1124,7 @@ private void keyListbox( int gadnum, char chr, int key )
default:
if( chr == 10 )
{
action( gadnum );
action( gadnum, shift );
}
break;
}
Expand Down Expand Up @@ -1693,7 +1693,7 @@ private void escape( int gadnum )
}
}

private void action( int gadnum )
private void action( int gadnum, boolean shift )
{
try
{
Expand Down Expand Up @@ -1726,13 +1726,17 @@ private void action( int gadnum )
else
{
selectedFile = gadItem[ GADNUM_DIR_LISTBOX ];
load( file );
load( file, shift );
}
}
else
{
selectedFile = 0;
listDir( file.getParentFile() );
file = file.getParentFile();
if( file != null )
{
selectedFile = 0;
listDir( file );
}
}
}
break;
Expand Down Expand Up @@ -1808,8 +1812,6 @@ private void action( int gadnum )
play();
}
break;
default:
System.out.println( gadnum );
}
}
catch( Exception e )
Expand Down Expand Up @@ -2209,7 +2211,7 @@ private void optimize()
listInstruments();
}

private void load( File file ) throws IOException
private void load( File file, boolean shift ) throws IOException
{
String extension = file.getName().toLowerCase();
if( extension.length() > 3 )
Expand All @@ -2220,13 +2222,16 @@ private void load( File file ) throws IOException
{
loadWav( file, 0 );
}
else if( extension.equals( ".iff" ) )
{
loadIff( file );
}
else if( extension.equals( ".raw" ) )
else if( extension.equals( ".iff" ) || extension.equals( ".raw" ) || shift )
{
loadRaw( file );
try
{
loadIff( file );
}
catch( IllegalArgumentException e )
{
loadRaw( file );
}
}
else
{
Expand Down

0 comments on commit 7f4b2fe

Please sign in to comment.